Bundle类

来源:互联网 发布:北明软件 中标 编辑:程序博客网 时间:2024/06/04 18:03

<1>在一个Activity中通过Bundle写入数据.
Intent openWelcomeActivityIntent=new Intent();
Bundle myBundelForName=new Bundle();
myBundelForName.putString("Key_Name",inName.getText().toString());
myBundelForName.putString("Key_Age",inAge.getText().toString());
openWelcomeActivityIntent.putExtras(myBundelForName);
openWelcomeActivityIntent.setClass(AndroidBundel.this, Welcome.class);
startActivity(openWelcomeActivityIntent);


<2>从另一个Activity中获取数据.
Bundle myBundelForGetName=this.getIntent().getExtras();
String name=myBundelForGetName.getString("Key_Name");
myTextView_showName.setText("欢迎您进入:"+name);


<3>总结:

简单来说,Bundle的作用就是为了传递数据,比如可以用在两个Activity之间,将一个Activity的数据传递到另一个Activity中.

0 0