小编Kur*_*sta的帖子

FragmentContainerView 作为 NavHostFragment

似乎FragmentContainerView不能立即使用?

<androidx.fragment.app.FragmentContainerView
        class="androidx.navigation.fragment.NavHostFragment"
        android:id="@+id/fragment_nav_host"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_app" />
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码fragment-ktx:1.2.0-rc01,我总是收到此错误:

Caused by: java.lang.IllegalStateException: Activity ...MainActivity@797467d does not have a NavController set on 2131296504
Run Code Online (Sandbox Code Playgroud)

仅使用<fragment>作品和 AFAIK,它应该被替换为FragmentContainerView.

我是不是遗漏了什么,或者有人可以FragmentContainerView用作NavHostFragment?

非常感谢!

navigation android fragment

75
推荐指数
3
解决办法
2万
查看次数

使用架构组件进行多模块导航

所以我在我当前的应用程序中为我的模块设置了这个结构.

应用模块结构

我还没有找到任何有关多模块导航的官方文档,但我发现这篇文章的内容是关于这一点的,这里是我的gradle文件的方式:

特征1 - 细节

...
implementation project(":base")
implementation project(":feature-2-detail")
...
Run Code Online (Sandbox Code Playgroud)

特征2 - 细节

...
implementation project(":base")
implementation project(":feature-1-detail")
...
Run Code Online (Sandbox Code Playgroud)

特征3 - 细节

...
implementation project(":base")
implementation project(":feature-1-detail")
...
Run Code Online (Sandbox Code Playgroud)

这是我的导航图:

特征1 - 细节

<navigation ...
    android:id="@+id/graph_feature_1_id">
    <include app:graph="@navigation/graph_feature_2" />
    <fragment ...
        android:id="@+id/nav_feature_1">
        <action ...
            app:destination="@+id/graph_feature_2_id" />

    </fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)

特征2 - 细节

<navigation ...
    android:id="@+id/graph_feature_2_id">
    <include app:graph="@navigation/graph_feature_1" />
    <fragment ...
        android:id="@+id/nav_feature_2">
        <action ...
            app:destination="@+id/graph_feature_1_id" />

    </fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)

特征3 - 细节

<navigation ...
    android:id="@+id/graph_feature_3_id">
    <include app:graph="@navigation/graph_feature_1" />
    <fragment ...
        android:id="@+id/nav_feature_3"> …
Run Code Online (Sandbox Code Playgroud)

android android-architecture-components android-architecture-navigation

13
推荐指数
2
解决办法
2609
查看次数

协程中未捕获异常

我似乎无法在协程中完成错误处理。我一直在阅读很多文章和异常处理文档,但我似乎无法让它工作。

这是我的设置:

ViewModel用它的范围启动协程

class MyViewModel(private var myUseCase: MyUseCase) : ViewModel() {
    private val viewModelJob = Job()
    private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob)

    fun doSomething() {
        uiScope.launch {
            try {
                myUseCase()
            } catch (exception: Exception) {
                // Do error handling here
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

UseCase只处理一些逻辑,在这种情况下是某种验证器

class MyUseCase(private val myRepository: MyRepository) {
    suspend operator fun invoke() {
        if (checker()) {
            throw CustomException("Checker Failed due to: ...")
        }

        myRepository.doSomething()
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我Repository只是处理网络层/本地层

object …
Run Code Online (Sandbox Code Playgroud)

android kotlin kotlin-coroutines

9
推荐指数
1
解决办法
2579
查看次数

动态功能模块的合并测试 apk

有没有办法为仪器测试创建通用 APK?我想在 Firebase 测试实验室上运行整个测试套件,但为每个动态功能模块的测试 APK 上传一个 APK 似乎很乏味。

对于该应用程序,您可以执行以下操作,packageVariantUniversalApk但我似乎找不到用于测试 APK 的任何内容。

任何帮助将不胜感激。

android firebase-test-lab instrumented-test dynamic-feature dynamic-feature-module

5
推荐指数
1
解决办法
128
查看次数