WAI
Status Update
Comments
jb...@google.com <jb...@google.com> #2
Could you please upload a minimum sample project that reproduces the issue?
The case reported in
[Deleted User] <[Deleted User]> #3
Sorry for delay.
I attached newly created project with the issue. (also included video of crash).
I attached newly created project with the issue. (also included video of crash).
il...@google.com <il...@google.com> #4
You can't use app:navGraph="@navigation/nav_graph" if you're modifying the graph at runtime - when you rotate your device, the graph, without your modifications, will be loaded and that original graph does not have your destinations. You need to use setGraph() with your modified graph.
You should look at the dynamic feature module support documentation, which is coming soon:
[Deleted User] <[Deleted User]> #5
Understand.
I saw the dynamic feature module support, but I wanted to start with dynamic modules which always be part of the app (for the better build support).
I didn't want to use the navigation-dynamic as it's still in development.
So in my case, if I'd have single-activity app and:
- I should not set app:navGraph
- in MainActivity::onCreate()
navController = findNavController(R.id.nav_host_fragment)
// this was previously set to app:navGraph
val mainGraph = navController.navInflater.inflate(R.navigation.nav_graph)
// the feature module graph
val crashGraph = navController.navInflater.inflate(R.navigation.nav_crash)
mainGraph.addDestination(crashGraph)
// similarly for all other feature modules, initialize here
// ...
// set the final graph
navController.graph = mainGraph
This setup works. Thanks
I saw the dynamic feature module support, but I wanted to start with dynamic modules which always be part of the app (for the better build support).
I didn't want to use the navigation-dynamic as it's still in development.
So in my case, if I'd have single-activity app and:
- I should not set app:navGraph
- in MainActivity::onCreate()
navController = findNavController(R.id.nav_host_fragment)
// this was previously set to app:navGraph
val mainGraph = navController.navInflater.inflate(R.navigation.nav_graph)
// the feature module graph
val crashGraph = navController.navInflater.inflate(R.navigation.nav_crash)
mainGraph.addDestination(crashGraph)
// similarly for all other feature modules, initialize here
// ...
// set the final graph
navController.graph = mainGraph
This setup works. Thanks
il...@google.com <il...@google.com> #6
Yep, that's exactly right. Glad you got it working!
eg...@gmail.com <eg...@gmail.com> #7
it works! thank You man!!
Description
Version used: 2.2.0-rc04
Devices/Android versions reproduced on: emulator Pixel 3 API 29
Similar bug was reported before
although version 2.1.0-alpha04 fixed the issue, in newest version the crash occurs again.
Upon screen rotation (or activity recreation), the app crashes when adding graph programmatically.
Steps to reproduce:
1) add subgraph programmatically
val subGraph = findNavController().navInflater.inflate(R.navigation.navigation_test)
findNavController().graph.addDestination(subGraph)
2) navigate to the subgraph
findNavController().navigate(MainFragmentDirections.actionMainFragmentToNavigationTest())
3) rotate screen
Caused by: java.lang.IllegalStateException: unknown destination during restore: com.strv.mlyko.kitchensink:id/navigation_test
at androidx.navigation.NavController.onGraphCreated(NavController.java:557)
at androidx.navigation.NavController.setGraph(NavController.java:534)
at androidx.navigation.NavController.setGraph(NavController.java:499)
at androidx.navigation.NavController.setGraph(NavController.java:481)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:237)
at com.strv.mlyko.kitchensink.presentation.main.CustomNavHostFragment.onCreate(MainActivity.kt:42)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:252)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1215)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:133)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.inflate(LayoutInflater.java:659)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:158)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:312)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at com.strv.mlyko.kitchensink.presentation.main.MainActivity.onCreate(MainActivity.kt:22)