当前页面传出参数:
public void First(View v){ //新建一个显式意图,第一个参数为当前Activity类对象,第二个参数为你要打开的Activity类 Intent intent =new Intent(FirstActivity.this,SecondActivity.class); //用Bundle携带数据 Bundle bundle=new Bundle(); //传递name参数 bundle.putString("name", "data"); intent.putExtras(bundle); startActivity(intent); }新页面接收参数: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.newtest); //新页面接收数据 Bundle bundle = this.getIntent().getExtras(); //接收name值 String name = bundle.getString("name"); Log.i("获取到的name值为",name); }
参数传递支持多个参数,同样使用,多次使用: bundle.putString("name0", "data"); intent.putExtras(bundle); bundle.putString("name1", "data"); intent.putExtras(bundle); 注意设置不同的标签,在接收时分别接收即可: Bundle bundle = this.getIntent().getExtras(); String name = bundle.getString("name0");Bundle bundle = this.getIntent().getExtras(); String name = bundle.getString("name1");