Bundle bundle = this.getIntent().getExtras();
if(bundle !=null){
Fragment、getArguments()
传
public static DriverHistoryFragment getInstance(String tag) { Bundle bundle = new Bundle(); bundle.putString(TAG, tag); DriverHistoryFragment fragment = new DriverHistoryFragment(); fragment.setArguments(bundle); return fragment; }
DriverHistoryFragment.getInstance(HISTORY)
取
mEnterTag = getArguments().getString(TAG);
传递
Intent intent = new Intent(GoodsDetailActivity.this, BuyOrderActivity.class);
intent.putExtra("datas", (Serializable) orderList);
intent.putExtra("type", BuyOrderActivity.SINGLE);
startActivity(intent);
intent.putExtra("put_ser_test",dto );
接收
mto = (BindCheckDTO)getIntent().getSerializableExtra("put_ser_test");
private List<OrderCommodity> orderList;
orderList = (List<OrderCommodity>) getIntent().getSerializableExtra("datas");
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("goodsBeans", goodsBeans);
bundle.putString("totalPrice", totalPrice);
bundle.putString("orderId", orderId);
intent.putExtras(bundle);
context.startActivity(intent);
goodsBeans = getIntent().getParcelableArrayListExtra("goodsBeans");
startActivityForResult的使用
发起跳转
List<CarBean.DataBean.ListBean> selectdatalist = new ArrayList<>();
public static final int REQUEST_CODE_CAR = 10002;
startActivityForResult(MoreCarActivity.newIntent(this, true), REQUEST_CODE_CAR);
回调接收数据
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
}
if (data != null) {
switch (requestCode) {
case REQUEST_CODE_CAR:
selectdatalist = (List<CarBean.DataBean.ListBean>) data.getSerializableExtra(CarActivity.RESULT_BEAN);
setCarInfo();
break;
}
}
}
返回数据
public static final String RESULT_BEAN = "result_bean";
Intent mIntent = new Intent();
mIntent.putExtra(RESULT_BEAN, (Serializable)selectdatalist);
setResult(RESULT_OK, mIntent);
finish();
//回到首页
Intent mainIntent = MainActivity.getIntent(BatteryOrderActivity.this, 4);
//打开订单列表
Intent orderListIntent = new Intent(BatteryOrderActivity.this, MyBatteryOrderActivity.class);
//打开订单明细
Intent orderDetailIntent = BatteryOrderDetailsActivity.getIntent(BatteryOrderActivity.this, orderId);
startActivities(new Intent[]{mainIntent, orderListIntent, orderDetailIntent});
回去
setResult(RESULT_OK);
接收
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
}
switch (requestCode) {
case REQUEST_CODE_RELEASE:
mViewpager.setCurrentItem(0);
mNewOrdersFragment.mRefreshLayout.startRefresh();
break;
}
}
发送。。REQUEST_QR_CODE 是请求码
Intent i = new Intent(MainActivity.this, SimpleCaptureActivity.class); MainActivity.this.startActivityForResult(i, REQUEST_QR_CODE);
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); LgqLogPlus.d("cccccc==请求码==="+requestCode+".。。。返回码..."+resultCode); if (resultCode == 3 && requestCode == REQUEST_QR_CODE && data != null) { String result = data.getStringExtra("function_test"); Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show(); } }
返回 3是返回码
Intent intent = new Intent(); intent.putExtra("function_test",resultString); setResult(3, intent); finish();