1.从AActivity跳转到BActivity,不需要传递参数
Intent intent = new Intent(AActivity.this,BActivity.class); //intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);//设置Activity的打开方式 startActivity(intent);
2.从AActivity跳转到BActivity,并向BActivity传递参数
向BActivity传递参数
Intent intent = new Intent(AActivity.this,BActivity.class); intent.putExtra("key1","value1"); intent.putExtra("key2","value2"); //... startActivity(intent);
在BActivity中获取AActivity传过来的参数
//获取前一个Activity传递的instance_id Bundle extras = getIntent().getExtras(); String value1 = extras.getString("key1"); String value2 = extras.getString("key2");
3.从AActivity跳转到BActivity,退出BActivity时向AActivity返回参数
AActivity中:
Intent intent = new Intent(AActivity.this,BActivity.class); startActivityForResult(intent,1);
评论