首页 > 代码库 > 不带数据和返回的Activity跳转

不带数据和返回的Activity跳转

public class MainActivity extends Activity {
  Button bt;
  Context context;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  context = this;   //存放当前Activity的实例
  setContentView(R.layout.activity_main);
  bt = (Button)findViewById(R.id.bt);
  bt.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View arg0) {
    setContentView(R.layout.second);
    Intent intent = new Intent(context,Second.class);    //设置此Activity跳转到另一个Activity
    startActivity(intent);    //启动目标Activity
        }
      });
    }
}

 

public class Second extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.second);
  Intent intent = getIntent(); //接受起始Activity传递过来的Activity
}

 

不带数据和返回的Activity跳转