Fragment中通过路由跳转到Activity
-
跳转传递参数
通过Arouter跳转
Postcard postcard = ARouter.getInstance().build(RouterConstant.ACTION_TRANSMANAGERACTIVITY1);
Bundle bundle = new Bundle();
bundle.putInt("code", 404);
postcard.with(bundle); //设置bundle
fragmentNavigation(postcard,10000);
private void fragmentNavigation(Postcard postcard , int requestCode) {
LogisticsCenter.completion(postcard);
Intent intent = new Intent(getActivity(),postcard.getDestination());
intent.putExtras(postcard.getExtras());
startActivityForResult(intent, requestCode);
}
- Activity中获取参数
ARouter.getInstance().inject(this);
num = getIntent().getExtras().getInt("code");
注意传递的参数Bundle也可以如下传递Bundle参数
设置Bundle参数
postcard.withBundle("Bundle",bundle);
Activity中获取Bundle参数
getIntent().getBundleExtra("Bundle").getInt("code");
在Activity中返回时别忘记了设置结果或者参数:
setResult(Activity.RESULT_OK);
Fragment总就可以重写onActivityResult方法,在此方法获取上一个Activity返回来的数据了或者处理相关业务逻辑了;
注意onActivityResult方法中int requestCode, int resultCode的区别;