Activity生命周期
Activity启动模式
Intent跳转
_________startActivity()
1.Intent intent=new Intent(A.this,B.class);
startActivity(intent);
2.startActivity(new Intent(A.this,B.class));
_________startActivityForResult()
Intent intent=new Intent(A.this,B.class);
1.当前界面中,接收结果
==>startActivityForReult(intent,101);//请求码requestCode
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==101){}}
2.跳转页面中,传递结果
==>setRusult(101,intent)//RESULT_CODE101结果码
Activity.this.finish();
startActivityForReult案例
Intent数据
A中传递数据
Intent intent=new Intent(A.this,B.class);
String data="data";
intent.putExtra("key",data);
startActivity(intent);B中接收数据
Intent intent=getIntent();
String data=intent.getStringExtra("key")
Bundle数据包方式
A中传递数据
Bundle bundle=new Bundle();
bundle.putString("name","DQ")
Intent intent=new Intent(A.this,B.class);
intent.putExtras(bundle)
startActivity(intent);B中接收数据
Intent intent=getIntent();
Bundle bundle=intent.getExras()
String data=bundle.getStringExtra("name")