I'm developing an app that has a LoginFragment
and HomeFragment
.
And I'm using jetpack navigation component for handling fragment navigations.
In the first, after that user completed the login proccess in LoginFragment
I call popBackStack()
then I navigate user to HomeFragment
.
The problem appear when the user clicked on dark mode
button.
I call recreate()
on activity.
And I need to Restore the NavHost again But I cleared the StartDestination
of that navHost.
What Can I do to solve this problem?
Note: I tried using popUpTo
; but that not worked for me.
You should not be using login as the start destination of your graph as per the Principles of Navigation:
Instead, follow the guide for doing Login in the Navigation Component and navigate to your login screen conditionally (i.e., only when the user is not logged in).