1. 只负责启动
Intent intent = new Intent(mContext, BookOrderActivity.class); Bundle mEmployeeBundle = new Bundle(); intent.putExtras(mEmployeeBundle); startActivity(intent);
2. A启动B, 需要B处理后返回的数据,使用startActivityForResult()方法
Activity A代码实现:
Intent intentDateSetting = new Intent(mContext, DateSettingActivity.class); startActivityForResult(intentDateSetting,requestCodeDateSetting ); //第二个参数为自定义的一个整数常数
接收从B返回的数据需要实现onActivityResult()方法
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode == DateSettingActivity.DATE_RESULT_CODE){ String date = data.getStringExtra(DateSettingActivity.DATE_KEY); mTvStartTime.setText(date); } }
B中返回数据实现
Intent intent = this.getIntent();
intent.putExtra(DATE_KEY, dateFormat.format(calendar.getTime()));
setResult(DATE_RESULT_CODE, intent);//发送结果给调有者,在此发送的是当时时间, 通过resultCode来取得
finish(); //关闭自身