Is it safe to call NavController navigation functions from a Composable outside NavHost?


CODE DESCRIPTION

In my code, I use a coordinator that triggers navigation to a screen when a specific condition is met.

I’m wondering whether this structure is safe:

MyAppNavHost() CoordinatorForceUpdateSheet(navigateToForceUpdate)

Everything seems to work correctly, but I’m worried that in some cases it might throw an exception:

java.lang.IllegalStateException: You must call setGraph() before calling getGraph()

PROBLEM

Can I rely on the NavHost graph being attached to the NavController before the coordinator triggers navigation? Or should I explicitly guard against calling navigation before the NavHost is initialized?

0
May 25 at 9:53 AM
User AvatarStanisław Olszak
#android#android-jetpack-compose#android-jetpack-navigation

No answer found for this question yet.