I am using Navigation Component to handle navigations, but when use popBackStack()
or onBackPressed()
to back to previous fragment my onViewCreated
call again in fragment with api and set up views.
Since Navigation Component 2.4 unveiled new features (popUpToSaveState and restoreState), i want to use it. please tell me how?
Asked
Active
Viewed 2,754 times
5

reza_khalafi
- 6,230
- 7
- 56
- 82
-
1You still need to use the [Fragment APIs to save your state](https://developer.android.com/guide/fragments/saving-state); `onViewCreated()` being called is still expected. – ianhanniballake Jun 12 '21 at 20:39
-
@reza_khalafi Have you solved this? – Rethinavel Nov 22 '21 at 12:29
1 Answers
-2
Even though you save your state onViewCreated will be called.
you need to use to save state.
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
}
and restore it on onCreate.

vignesh
- 492
- 3
- 9