使用Bundle在Activity间传递数据
来源:互联网 发布:网络安全法实施方案 编辑:程序博客网 时间:2024/06/06 15:37
\1、使用Bundle在Activity间传递数据1
从源Activity 中传递数据
//数据写入Intent
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);
目标Activity 中获取数据
//从Intent 中获取数据
Bundle myBundelForGetName=this.getIntent().getExtras();
String name=myBundelForGetName.getString("Key_Name");
myTextView_showName.setText("欢迎您进入:"+name);
2、使用Bundle在Activity间传递数据2
从源请求Activity 中通过一个Intent 把一个服务请求传到目标Activity 中
private Intent toNextIntent;//Intent 成员声明
toNextIntent=new Intent();//Intent 定义
toNextIntent.setClass(TwoActivityME3.this, SecondActivity3.class);
//设定开启的下一个Activity
startActivityForResult(toNextIntent, REQUEST_ASK);
//开启Intent 时候,把请求码同时传递
在源请求Activity 中等待Intent 返回应答结果,通过重载onActivityResult()方法
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==REQUEST_ASK){
if(resultCode==RESULT_CANCELED){
setTitle("Cancel****");
}else if(resultCode==RESULT_OK){
showBundle=data.getExtras();//从返回的Intent中获得Bundle
Name=showBundle.getString("myName");//从bundle中获得相应数据
text.setText("the name get from the second layout:\n"+Name);
}
}
}
? 第一个参数是你开启请求Intent时的对应请求码,可以自己定义。
? 第二个参数是目标Activity返回的验证结果码
? 第三个参数是目标Activity返回的Intent
目标Activity 中发送请求结果代码,连同源Activity 请求的数据一同绑定到Bundle
中通过Intent 传回源请求Activity 中
backIntent=new Intent();
stringBundle=new Bundle();
stringBundle.putString("myName", Name);
backIntent.putExtras(stringBundle);
setResult(RESULT_OK, backIntent);//返回Activity结果码
finish();
- 使用Bundle在Activity间传递数据
- 使用Bundle在Activity间传递数据
- 使用 Bundle在Activity间传递数据
- 使用Bundle在Activity间传递数据
- 使用bundle在activity间传递数据
- 使用Bundle在Activity之间传递数据
- 使用Bundle在Activity之间传递数据
- 使用bundle在Activity之间传递数据
- 使用Intent Bundle在Activity间传递数据
- Android 使用Bundle在Activity间传递数据
- 使用Bundle在Activity间传递信息
- 在安卓中使用Bundle在Activity之间传递数据
- 使用bundle在多个activity之间传递数据
- 使用Bundle在Activity之间进行数据传递
- 使用Bundle在Activity中来传递数据
- Android中用Bundle在Activity间传递数据
- 使用Bundle在Activity之间传递信息
- 使用Bundle在fragment之间传递数据
- 各种排序算法C++模版类实现
- TCMalloc
- Ubuntu 10.04配置Apache+PHP+MySQL
- zedGraph 鼠标悬停 显示内容
- SharePoint2010创建MySite
- 使用Bundle在Activity间传递数据
- TCMalloc:线程缓存的Malloc
- Processor ARM79_0 raised a exception. cause: unrecognised SWI
- 图的邻接表和邻接矩阵
- Java数据结构(栈,队列,双链表)
- HttpResponse的Output与OutputStream、Filter关系
- JAVA 使用网络传输文件 并且使用原来的文件名称(服务端改进版)
- HDU_1824 Let's go home 2-Sat
- Java 三元运算符( ?:) 的幽默