今天我们来学习一下在 app 程序里面的不同 Activity 活动页之间传递参数的方法
准备两个 Activity,一个是 PageA,一个是 PageB
在 PageA 里编写代码
Intent intent = new Intent();
Bundle bundle = new Bundle();
intent.setClass(PageA.this, PageB.class);
bundle.putString("sArg", "this is string");
bundle.putInt("iArg", 123);
intent.putExtras(bundle);
startActivity(intent);在 PageB 里编写代码
try {
Bundle bundle;
bundle = this.getIntent().getExtras();
sArg = bundle.getString("sArg");
iArg = bundle.getInt("iArg");
}
catch (Exception e){
e.printStackTrace();
return;
}