Android

安卓代码段--传递Bundle数据

2016-08-31  本文已影响67人  tea9

Intent intent=new Intent(MainActivity.this,TestAcitvity.class);
Bundle bundle=new Bundle();
bundle.putString("name","shaomiao");
bundle.putInt("age",17);
///////
intent.putExtras(bundle);
startActivity(intent);


Intent i=getIntent();
///////////
Bundle bundle=i.getExtras();
TextView textView= (TextView) findViewById(R.id.textView);
textView.setText(String.format("name%s,age%d",bundle.getString("name"),bundle.getInt("age")));


第二种:
Intent intent=new Intent(MainActivity.this,TestAcitvity.class);
Bundle bundle=new Bundle();
bundle.putString("name","shaomiao");
bundle.putInt("age",17);
////////
intent.putExtra("data",bundle);
startActivity(intent);


Intent i=getIntent();
Bundle bundle=i.getBundleExtra("data");
TextView textView= (TextView) findViewById(R.id.textView);
textView.setText(String.format("name%s,age%d",bundle.getString("name"),bundle.getInt("age")));

上一篇下一篇

猜你喜欢

热点阅读