`

两个activity之间的Intent 传值

阅读更多

看了很多,总结以下首先activity1和activity2之间

 

activity1的时候

传值{

   Intent intent = new Intent();
   intent.setClass(SoundListenActivity.this, appset.class);
   Bundle bundle =new Bundle();
   bundle.putString("phonenum", phonenum);
   bundle.putLong("threhode", threhode);
   intent.putExtras(bundle);
   startActivityForResult(intent, 1);

 

@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  // TODO Auto-generated method stub
  super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == 1) {
   Bundle bundle = data.getExtras();
   
   phonenum = bundle.getString("phonenum");
   threhode = bundle.getLong("threhode");

}

 

activity2里面

 

protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.appset);
  
   Intent intent =new Intent();
  Bundle bundle =getIntent().getExtras();
  String phonenum=bundle.getString("phonenum");
  Long threhode=bundle.getLong("threhode");
  System.out.println("appset-->>"+phonenum+">>"+threhode);
    
 }

 

返回传值的程序是

Intent intent = new Intent();
    intent.setClass(appset.this, SoundListenActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString("phonenum", phone);
    bundle.putLong("threhode", threhode);
    intent.putExtras(bundle);
    setResult(1,intent);
    finish();

 

加粗的那几个地方,需要注意!谢谢

分享到:
评论

相关推荐

    Android 中两个Activity 之间的传值问题

    主要介绍了Android 中两个Activity 之间的传值问题的相关资料,需要的朋友可以参考下

    Android开发 两个Activity之间通过Intent跳转传值

    详细的介绍可以参考我的博客

    android开发中Intent在两个Activity间传值示例

    android开发中Intent在两个Activity间传值示例

    intent传值

    intent 两个activity 通过intent进行值得传递

    Android课程第二次实验报告-Intent传值.docx

    实现Intent跳转及传值.用Intent方式建立两个Activity页面如下

    android中Intent传值与Bundle传值的区别详解

    举个例子我现在要从A界面跳转到B界面或者C界面 这样的话 我就需要写2个Intent如果你还要涉及的传值的话 你的Intent就要写两遍添加值的方法 那么 如果我用1个Bundle 直接把值先存里边 然后再存到Intent中 不就更...

    Android学习笔记–Activity中使用Intent传值示例代码

    Intent,又称为意图,是一种运行时绑定机制,它能在程序运行的过程中链接两个不同的组件(Activity、Service、BroadcastReceiver)。通过Intent,程序可以向Android表达某种请求或意愿,Android会根据意愿的内容选择...

    intent切换activity listview获得回传值

    在一个应用中创建多个Activity的方法,掌握通过Intent在两个Activity之间进行切换的方法,掌握通过Intent在两个Activity之间进行数据传递的方法,掌握在一个Activity中启动并监听新的Activity返回值的方法。

    activity跨进程调用

    两个项目,一个调用者一个别调用者,涉及到了intent 传值,接收,启动模式

    详解intent

    当一个application 中有多个 Activity的时候,那么每个Activity之前的传值就是一个问题了。所以这里介绍一下相关的方法。 在Android平台传值,主要使用两种方法一个事 PendingIntent 另一个就是广播了 按照大类,...

    利用Application 在2个不同的Activity传递数据

    利用Application 在2个不同的Activity传递数据 可以用做保存帐号的登录信息

    Android startActivityForResult实例详解

    startActivityForResult用于两个activity之间的数据传递,Activity1传值给Activity2,Activity2再返回值给Activity1。 第一步:Activity1中:startActivityForResult(Intent intent, Int requestCode) Intent ...

    Android 开发技巧

    9.52、获得两个GPS坐标之间的距离 276 9.53、通过经纬度显示地图 277 9.54、路径规划 277 9.55、将坐标传递到GOOGLE MAP并显示 277 9.56、获取本机电话号码 280 9.57、获得手机联系人 280 9.58、2.0以上版本查询联系...

    Android开发资料合集-World版!

    9.52、获得两个GPS坐标之间的距离 276 9.53、通过经纬度显示地图 277 9.54、路径规划 277 9.55、将坐标传递到GOOGLE MAP并显示 277 9.56、获取本机电话号码 280 9.57、获得手机联系人 280 9.58、2.0以上版本查询联系...

    Android开发资料合集--续

    1、Bundle传值 15 2、利用startActivityForResult与onActivityResult方法 16 11、使程序完全退出 18 12、列出所有音乐文件 18 13、使用Intent ACTION 调用系统程序 19 显示网页: 19 显示地图: 19 路径规划: 19 拨打...

Global site tag (gtag.js) - Google Analytics