How do I exit `androidx.navigation`'s navGraph-sco...
# android
j
How do I exit `androidx.navigation`'s navGraph-scoped viewmodel scope so that those viewmodels can be destroyed, and then reconstructed when I re-enter the navGraph's scope? Right now, I am calling
(context as Activity).finish()
inside my fragment, but that doesn't seem to be right.
i
That automatically happens when you pop the last destination that is the part of that graph off the back stack
c
If your project is SAA, why not?
j
I can't seem to
popBackStack
into the calling activity(that is not part of the nav_graph). This is how I start the activity that inflates the navGraph
Copy code
startActivity(Intent(applicationContext, MainActivity::class.java))
finish()
i
That seems like an entirely different question than your original question?
j
Well yes, this is my result after trying your solution
I'm not sure if I'm inflating/exiting the navgraph correctly now
i
Sounds like a bit of an XY Problem kind of situation: https://xyproblem.info/
It isn't clear how 'when I re-enter the navGraph's scope' was tied to you having multiple activities
But yes, the documentation does specifically call out when you manually pop the last destination on your back stack by returning false - that's when you need to manually finish your activity: https://developer.android.com/guide/navigation/navigation-navigate#back-stack
But if you're in those kind of cases, you're probably a bit far off the beaten path