在BottomNavigation中在它们之间快速切换时片段崩溃

问题描述 投票:0回答:1

我有MainActivity,里面有BottomNavigation,可以通过以下方法加载片段

private boolean loadFragment(Fragment fragment) {
        //switching fragment
        if (fragment != null) {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.fragment_container, fragment)
                    .commit();
            return true;
        }
        return false;
    }

[当我在它们之间快速切换时,我的应用程序在各个地方崩溃,但是当我慢慢走一遍时,一切正常。

这是我的应用程序结构的外观

enter image description here

我正在使用Reteofit进行API调用

我已经尝试过setuserVisibleHint还要检查是否创建了我的视图rootView

android fragment bottomnavigationview
1个回答
0
投票

我正在使用改造来获取API的响应,然后将其传递给适配器,但是由于使用底部导航和片段的快速切换,我的应用程序崩溃了,因为hideProgressBar()抛出NullException。我观察到视图被破坏,然后小部件无法执行。

因此,我进行检查以确保该视图不为空。它解决了我的情况。我希望它可以帮助正在寻找相同解决方案的其他人。

在Kotlin中:视图和Java:getView()(在Java中)

enter image description here

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.