Clear Navigation back stack and Recreating activity

888 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

You should not be using login as the start destination of your graph as per the Principles of Navigation:

Note: An app might have a one-time setup or series of login screens. These conditional screens should not be considered start destinations because users see these screens only in certain cases.

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).