https://kotlinlang.org logo
Title
m

manlan

07/05/2020, 7:46 AM
I am moving from Fragment A to Fragment B. When I press back button, Fragment A is recreated. I wish to avoid this. How do I do it? I am using Navigation Component e.g.
findNavController().navigate(R.id.showDetailScreen)
g

gildor

07/05/2020, 8:27 AM
Fragment probably not recreated, but view does But anyway, it's not related to Kotlin
👍 1
🙂 1
v

Viktor Petrovski

07/05/2020, 8:58 AM
Yeah this is the standard behavior using NavigationComponent. You should keep your data in a scoped ViewModel and observe it from view/fragment. This way even when navigating back you will present them with the data they’ve left the screen.
👍🏼 1
m

manlan

07/06/2020, 3:38 AM
@Viktor Petrovski Thank you 🙂