Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Fix IllegalStateException does not have a NavController set #2

Open
VictorAlbertos opened this issue Jul 1, 2020 · 2 comments
Open

Comments

@VictorAlbertos
Copy link
Contributor

After bumping the navigation lib version to 2.3.0 our deep links stoped to work: when the user left the app on the background (by clicking the home button for instance) and a deep link was launched, the app crashed:

java.lang.RuntimeException: Unable to destroy activity {com.mufumbo.android.recipe.search.debug/com.cookpad.android.home.home.HomeActivity}: java.lang.IllegalStateException: View androidx.fragment.app.FragmentContainerView{3ef6e7d V.E...... ......ID 0,0-1080,1584 #7f0903e8 app:id/navigationHostFragment} does not have a NavController set
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5020)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5049)
        at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7476)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:939)
     Caused by: java.lang.IllegalStateException: View androidx.fragment.app.FragmentContainerView{3ef6e7d V.E...... ......ID 0,0-1080,1584 #7f0903e8 app:id/navigationHostFragment} does not have a NavController set
        at androidx.navigation.Navigation.findNavController(Navigation.java:84)
        at androidx.navigation.fragment.NavHostFragment.onDestroyView(NavHostFragment.java:388)
        at androidx.fragment.app.Fragment.performDestroyView(Fragment.java:2908)
        at androidx.fragment.app.FragmentManager.destroyFragmentView(FragmentManager.java:1344)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1264)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
        at androidx.fragment.app.FragmentManager.dispatchDestroy(FragmentManager.java:2609)
        at androidx.fragment.app.FragmentController.dispatchDestroy(FragmentController.java:330)
        at androidx.fragment.app.FragmentActivity.onDestroy(FragmentActivity.java:365)
        at androidx.appcompat.app.AppCompatActivity.onDestroy(AppCompatActivity.java:233)
        at android.app.Activity.performDestroy(Activity.java:8234)
        at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1344)
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5005)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5049) 
        at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44) 
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7476) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:939) 

We were not able to find the actual issue and the only way we found to bypass this limitation has been subclassing NavHostFragment to try/catch the call to super::onDestroyView and sallow this particular exception. We will keep this issue open to keep track of it hoping that future versions of the navigation library fix the issue in the same way it appeared: without knowing how.

VictorAlbertos added a commit that referenced this issue Jul 1, 2020
VictorAlbertos added a commit that referenced this issue Jul 1, 2020
VictorAlbertos added a commit that referenced this issue Jul 1, 2020
VictorAlbertos added a commit that referenced this issue Jul 1, 2020
VictorAlbertos added a commit that referenced this issue Jul 2, 2020
@silentnuke
Copy link
Contributor

@VictorAlbertos I tried to replace LenientNavHostFragment with NavHostFragment and then

  1. Launch the app.
  2. Open detail screen.
  3. Trigger notification.
  4. Background the app using home button.
  5. Open notification.

There is no crash.

Could you please provide more detailed steps to repro it? Is it easily reproducible or it's device specific?

@VictorAlbertos
Copy link
Contributor Author

We were not able to replicate the issue using the Watson sample app, only happened in the Cookpad Android app. And sadly we were not able to spot the actual cause of this issue 🤷

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants