首页 > 其他 > 详细

实现一个activity中传输信息到另一个activity

时间:2016-08-26 15:49:34      阅读:188      评论:0      收藏:0      [点我收藏+]

    android开发中经常需要处理各种各样不同的信息,而不同activity中发送和接收信息对于开发也是相当重要的。

方法一:

        发送方代码:

        Intent intent = new Intent(MainActivity.this,SecondActivity.class);                        Bundle bundle=new Bundle(); 

bundle.putInt("position", position);

intent.putExtras(bundle);

startActivity(intent);


        接收方代码:

        Bundle bundle = getIntent().getExtras();//获取从mainactivity中传过来的对象

int position = bundle.getInt("position");//根据设定的键值获取对应的信息

方法二:

        发送方:

Intent intent = new Intent(MainActivity.this,SecondActivity.class);

intent.putExtra("position", position);

intent.putExtra("name", name);

startActivity(intent);

        接收方:

        Intent intent = getIntent();

int position = intent.getIntExtra("position", 0);

String name = intent.getStringExtra("name");

        

接收到的内容就可以直接利用

本文出自 “11828641” 博客,请务必保留此出处http://11838641.blog.51cto.com/11828641/1842683

实现一个activity中传输信息到另一个activity

原文:http://11838641.blog.51cto.com/11828641/1842683

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!