I am currently in a situation where it might be unfeasible to refactor the whole app in order to make a more cohesive whole but the current approach to using Jetpack Navigation is causing crashes.
The app has multiple graphs, for the sake of simplicity let's call them:
Graph A,
Graph B,
Graph C
Graph A is set in the activity layout through app:navGraph and if it remains the only used graph the application can and will restore it's state after process death.
However at certain moments the app programatically switches the graphs by using the navController of the FragmentContainerView and calling setGraph(graphResId: Int) with the new graphs id provided. Before that manually inflating the graph was used as well.
Both approaches of setting the graph result in a crash after the first restart after process death and an exception thrown that says:
Unable to start activity ComponentInfo{com.appname.dev/com.appname.activity.MainActivity}: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination com.appname.dev:id/graph_b cannot be found from the current destination null
The exception occurs in MainActivity onCreate's call to super.onCreate()
The only solution in my mind that I can come up with is to include the other graphs in the first graph, use actions to navigate to the other graphs and therefor avoid switching graphs. However due to the way the application has been made that might end up being quite time consuming.
I am wondering if I am missing an important step that could mediate this crash.