Bundle类中加入数据(key -value的形式,另一个activity里面取数据的时候,就要用到key,找出对应的value)。
在TestBundle类中的代码:
Intent intent = new Intent();
intent.setClass(TestBundle.this, Target.class);
Bundle mBundle = new Bundle();
mBundle.putString("Data", "data from TestBundle");//压入数据
intent.putExtras(mBundle);
startActivity(intent);
在Target类中的代码:
Bundle bundle = getIntent().getExtras();
//得到传过来的bundle
String data = bundle.getString("Data");//读出数据