Android Fragment中使用Arouter跳转到Activity后返回Fragment不回调onActivityResult

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的区别;

相关推荐
双桥wow11 分钟前
Android Framework开机动画开发
android
fanged7 小时前
天马G前端的使用
android·游戏
molong93111 小时前
Kotlin 内联函数、高阶函数、扩展函数
android·开发语言·kotlin
叶辞树12 小时前
Android framework调试和AMS等服务调试
android
慕伏白14 小时前
【慕伏白】Android Studio 无线调试配置
android·ide·android studio
低调小一15 小时前
Kuikly 小白拆解系列 · 第1篇|两棵树直调(Kotlin 构建与原生承载)
android·开发语言·kotlin
跟着珅聪学java15 小时前
spring boot 整合 activiti 教程
android·java·spring
川石课堂软件测试16 小时前
全链路Controller压测负载均衡
android·运维·开发语言·python·mysql·adb·负载均衡
2501_9159214317 小时前
iOS 26 电耗监测与优化,耗电问题实战 + 多工具 辅助策略
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_9159214317 小时前
苹果软件混淆与 iOS 应用加固白皮书,IPA 文件加密、反编译防护与无源码混淆方案全解析
android·ios·小程序·https·uni-app·iphone·webview