【问题标题】:startActivityForResult() between Dynamic Feature Modules with Android Architecture Navigation具有 Android 架构导航的动态功能模块之间的 startActivityForResult()
【发布时间】:2020-10-01 18:08:05
【问题描述】:

我们有一个带有活动 A1 的图表 A,我们想使用 startActivityForResult() 打开带有活动 B1 的图表 B,以便将结果从 B1 传回 A1。

问题在于 A 和 B 图存在于单独的动态特征模块中,因此在 A1 中我们无法访问活动 B1 类来调用 startActivityForResult()。 我们确实连接了两个模块的导航图,以便我们可以在模块之间导航,但 Android 架构导航不支持startActivityForResult()

我们如何使用 Android 架构导航中定义的导航方向调用startActivityForResult()

【问题讨论】:

    标签: android android-architecture-navigation


    【解决方案1】:

    可以获取导航图中定义的操作的启动意图。 要实现它,您需要:

    1. 获取导航方向(NavDirections)
    2. 获取操作 ID 并使用它从导航控制器获取操作
    3. 从操作中获取目标 ID
    4. 使用目标 ID 在图中查找节点
    5. 从 ActivityNavigator.Destination 节点获取 Intent
    val direction = MyGeneratedDirections.actionOpenMyDestination(myParam)
    val destId = findNavController().currentDestination.getAction(direction.actionId).destinationId
    val intent = (findNavController().graph.findNode(destId) as? ActivityNavigator.Destination)?.intent
    

    https://developer.android.com/reference/androidx/navigation/ActivityNavigator.Destination#getIntent()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多