浏览量 4578
2014/04/21 02:05
1、通过bundle传值:
mainactivity:
Intent intent = new Intent();
intent .setClass(this, Command. class);
Bundle bundle = new Bundle();
bundle.putString( "title", title);
bundle.putInt( "statement", statement); // 要传递的数据
intent. putExtras(bundle);
startActivity(intent);
command activity:
int st= this.getIntent().getExtras().getInt( "statement");
String tt=this.getIntent().getExtras().getString( "title");
2、直接传值
主:
Intent intent=new Intent(MainActivity.this,NextActivity.class);
intent.putExtra("name","jack");
intent.putExtra("age",23);
intent.putExtra("address","北京");
Bundle bundle=new Bundle();
bundle.putString("code","1001");
intent.putExtra("bundle",bundle);
startActivity(intent);
副:
Intent intent=getIntent();
String name=intent.getStringExtra("name");
int age=intent.getIntExtra("age",0);
String address=intent.getStringExtra("address");
Bundle bundle=intent.getBundleExtra("bundle");
String code=bundle.getString("code");
上一篇 搜索 下一篇