手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android页面之间进行数据回传的方法分析
Android页面之间进行数据回传的方法分析
摘要:本文实例讲述了Android页面之间进行数据回传的方法。分享给大家供大家参考,具体如下:要求:页面1跳转到页面2,页面2再返回页面1同时返回...

本文实例讲述了Android页面之间进行数据回传的方法。分享给大家供大家参考,具体如下:

要求:页面1跳转到页面2,页面2再返回页面1同时返回数据

页面1添加如下代码:

Intent intent = new Intent(); intent.setClass(页面1.this, 页面2.class); Bundle bundle = new Bundle(); intent.putExtras(bundle);//将Bundle添加到Intent,也可以在Bundle中添加相应数据传递给下个页面,例如:bundle.putString("abc", "bbb"); startActivityForResult(intent, 0);// 跳转并要求返回值,0代表请求值(可以随便写)

页面2接收数据添加代码如下:

Intent intent = this.getIntent(); Bundle bundle = intent.getExtras(); bundle.putString("aaa", "back");//添加要返回给页面1的数据 intent.putExtras(bundle); this.setResult(Activity.RESULT_OK, intent);//返回页面1 this.finish();

页面1接收返回数据:(需要重写onActivityResult)

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 0 && resultCode == Activity.RESULT_OK) { Bundle bundle = data.getExtras(); gameView.backString = bundle.getString("aaa"); Toast.makeText(this, backString, Toast.LENGTH_SHORT).show(); } }

希望本文所述对大家Android程序设计有所帮助。

【Android页面之间进行数据回传的方法分析】相关文章:

Android中 自定义数据绑定适配器BaseAdapter的方法

Android中获取IMEI码的办法

android实现listview分页的方法

android 默认时间格式修改方法

Android从服务器获取图片的实例方法

android中ListView数据刷新时的同步方法

Android 有道词典的简单实现方法介绍

Android操作系统的架构设计分析

Android动画之3D翻转效果实现函数分析

在Android 模拟器上安装和卸载APK包的方法

精品推荐
分类导航