您的位置:首页 > 移动开发 > Android开发

Android 两个activity之间通信

2013-12-25 09:31 453 查看
两个activity之间可以通过bundle通信,比如我现在有两个Activity,ListViewActivity和ReplyActivity。

ListViewActivity中的代码:

//跳到报价界面
            	Intent intent = new Intent();
            	intent.setClass(ListViewActivity.this, ReplyActivity.class);
				Bundle bundle = new Bundle();
				bundle.putString("materialName", map.get("materialName").toString());
				bundle.putString("materialFormat", map.get("materialFormat").toString());
				bundle.putString("mapId", map.get("mapId").toString());
				intent.putExtras(bundle);
				// 转向登陆后的页面
				startActivity(intent);


ReplyActivity中通过this.getIntent()可以获得传过来的intent.

代码:

//获取上个页面传过来的intent
		intent = this.getIntent();
		//获取intent中的Bundle数据
		bundle = intent.getExtras();
		String materialName = bundle.getString("materialName");
		String materialFormat = bundle.getString("materialFormat");
		String mapId = bundle.getString("mapId");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: