使用    Intent 启动另一个 Activity
Intent  showNextPage_Intent=new  new  new  new  Intent();
showNextPage_Intent.setClass(UsingBundel.this    ,NextPageActivity.class);
startActivity(showNextPage_Intent);

在多个Activity 之间切换时候,注意每个  Activity 都应在 AndroidManifest.xml AndroidManifest.xml AndroidManifest.xml AndroidManifest.xml  中有所声明定义(如下)
<application  android:label="@string/app_name"
android:icon="@drawable/chinazphone" >
<activity  android:name=".UsingBundel"
android:label="@string/app_name" >
<intent-filter >
<action  android:name="android.intent.action.MAIN"  />
<category  android:name="android.intent.category.LAUNCHER"  />
</intent-filter>
</activity>
<activity  android:name=".NextPageActivity"
android:label="@string/nextpage" ></activity>
</application>
新的 Activity 在 AndroidManifest.xml 中必须定义声明

使用 Bundle  在 Activity间传递数据

从源请求 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  new  new  new  Intent();
stringBundle=new  new  new  new  Bundle();
stringBundle.putString("myName",  Name);
backIntent.putExtras(stringBundle);
setResult(RESULT_OK,  backIntent);// 返回 Activity 结果码

finish();

本文转自feisky博客园博客,原文链接:http://www.cnblogs.com/feisky/archive/2010/05/27/1745113.html,如需转载请自行联系原作者

使用 Bundle在Activity间传递数据相关推荐

  1. android finish()传参数,48. (android开发) activity间传递数据(打开浏览器、拨号盘、传参)...

    在 android 中多个 activity 中互相访问是常见的一种操作,比如:打开系统浏览器.显示系统拨号盘等等. 做这些操作的时候,自然是需要传递一些数据过去,比如:要打开的网址.要拨打的电话号码 ...

  2. AndroidStudio安卓原生开发_利用Activity的Intent 以及Bundle在activity之间传递数据---Android原生开发工作笔记91

    暂时不写内容,后边补上,因为工作太忙,先把图,以及重要的难点说明写出来,后边会修改成详细的文章

  3. Android之一窥究竟Activity间的数据传递以及Intent的用处

    1.Activity与Intent * 1.1何为Intent * 1.2Intent的用武之地 * 1.3Activity间的数据传递 转载请标明出处: http://blog.csdn.net/h ...

  4. 不同Activity之间传递数据--Bundle对象和startActivityForResult方法的实现

    首先,由于Activity是Android四大组件之一,如果一个应用程序中包含不止一个Activity,则需要在AndroidManifest.xml文件中进行声明. 例如进行如下的声明(程序中包含两 ...

  5. activity 点击后传递数据给fragment_Fragment 新特性 : Fragment Result API 使用以及源码分析

    原标题: Android Fragments: Fragment Result 原文地址: https://proandroiddev.com/android-fragments-fragment-r ...

  6. Android学习笔记之activity间传递传递参数

    activity间传递值 通过Intent启动另一个activity 传递简单数据(八大基本数据类型+String) 传递简单数据的代码片段 Intent intent = new Intent(Ma ...

  7. android 不同activity之间传递数据

    1> 不同activity之间传递数据: Intent intent=new Intent(); intent.setClass(activity1.this,activity2.class); ...

  8. 父activity启动子activity并传递数据

    1. Intent component : activity,service,broadcast receiver以及content provider component 与操作系统 通信的一种媒介工 ...

  9. StoryBoard学习(5):使用segue页面间传递数据

    StoryBoard学习(5):使用segue页面间传递数据 函数: C代码   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:( ...

最新文章

  1. 学习C语言深入解剖笔记之关键字的秘密
  2. PHP支付接口教程,详解微信支付(二)
  3. Junit如何进行多线程测试
  4. 深入一步研究DNS服务器
  5. php xml 接口调用,php的SimpleXML方法读写XML接口文件实例解析
  6. 高性能数据库集群:读写分离
  7. 奇讯新游 PHP,QXPLAY
  8. [SQL提数]函数的灵活使用
  9. C++实现RTMP协议发送H.264编码及AAC编码的音视频,摄像头直播
  10. mac系统vscode头文件not found
  11. hibou 主界面自定义侧滑
  12. VMware临时文件清理
  13. 使用Node搭建reactSSR服务端渲染架构
  14. MSF(3)——apk和exe的加马(过360、火绒)
  15. 太极图正确画法_道教知识:太极图的正确画法
  16. 把书读薄:《上帝掷骰子吗-量子物理史话》
  17. 2万字带你了解Selenium全攻略
  18. 【Gorho】springboot整合Shiro+jwt 前后端分离 超级详细的shiro+jwt鉴权过程
  19. # 研究杂感 × Gephi探秘飞升(第三辑)
  20. 华为鸿蒙系统强势来袭,华为鸿蒙系统强势来袭,取其精华,去其糟粕!

热门文章

  1. 飞桨深度学习开源框架2.0抢先看:成熟完备的动态图开发模式
  2. 「杂谈」同学聚会最悲哀的事情
  3. ICML 2020 | 小样本学习首次引入领域迁移技术,屡获新SOTA结果
  4. 5G+AI成产业新引擎 安防行业切入点在哪里?
  5. 图像识别落地机会最多 腾讯全面输出视觉AI
  6. GANs和ODEs:数学建模的终结?
  7. 机器学习里如何确定K-Means算法的K值?
  8. SAP WM Storage Type下不允许负库存的设置
  9. 骆利群院士最新Science综述:神经环路架构,激发新的AI
  10. 小目标检测的一些问题,思路和方案