ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

the app crashes #166

Closed prilaga closed 5 years ago

prilaga commented 6 years ago

@ncapdevi First of all, thank you for your great library. I use FragNav in the app, which is published on Google Play. The app crashes with this library, pleae look at the attached screenshot:

Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2053) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2079) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:678) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:632) at com.ncapdevi.fragnav.FragNavController.commitTransaction(FragNavController.java:742) at com.ncapdevi.fragnav.FragNavController.switchTabInternal(FragNavController.java:217) at com.ncapdevi.fragnav.FragNavController.switchTab(FragNavController.java:192) at com.prilaga.instagrabber.view.activity.MainActivity$setupNavigationBar$$inlined$let$lambda$1.onTabSelected(MainActivity.kt:358) at com.aurelhubert.ahbottomnavigation.AHBottomNavigation.updateItems(AHBottomNavigation.java:645) at com.aurelhubert.ahbottomnavigation.AHBottomNavigation.access$000(AHBottomNavigation.java:52) at com.aurelhubert.ahbottomnavigation.AHBottomNavigation$2.onClick(AHBottomNavigation.java:475) at android.view.View.performClick(View.java:4793) at android.view.View$PerformClick.run(View.java:19959) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5593) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

2018-09-13 19 11 21

Ustimov commented 6 years ago

Hi. I think you can find something helpful here https://github.com/ncapdevi/FragNav/pull/118 and here https://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa/10261438#10261438.

davit-zakariyan commented 1 year ago

@OlegTarashkevich How did you finally fix this issue on you side?

prilaga commented 1 year ago

@davit-zakariyan

Something like that:

    private fun showFragment(fragment: Fragment, tag: String) {
        try {
            // Try to avoid on some devices - Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
            fragment.show(supportFragmentManager, tag)
        } catch (e: IllegalStateException) {
            val transaction = supportFragmentManager.beginTransaction()
            transaction.add(fragment, tag)
            transaction.commitAllowingStateLoss()
        }
    }
davit-zakariyan commented 1 year ago

Thanks but your solution is for my fragments

@davit-zakariyan

Something like that:

    private fun showFragment(fragment: Fragment, tag: String) {
        try {
            // Try to avoid on some devices - Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
            fragment.show(supportFragmentManager, tag)
        } catch (e: IllegalStateException) {
            val transaction = supportFragmentManager.beginTransaction()
            transaction.add(fragment, tag)
            transaction.commitAllowingStateLoss()
        }
    }

Yeah but this is not related to fragNavController.switchTab(TabData.HOME.ordinal, options) So the crash actually happen here.

prilaga commented 1 year ago

@davit-zakariyan The best solution is to download the sources, import to your project and fix the place.