Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Navigation popBackStack

I tried use Android Navigation component and have a problem with back stack.

I have Fragment A, B. I write:

Navigation.findNavController(view).navigate(R.id.a_to_b)

It's ok. But if I want return to A, i call:

Navigation.findNavController(view).popBackStack();

Then in fragment B will be calling onViewStateRestored with null state why?

I want to keep state when calling navigate to Fragment A.

like image 915
alezhka Avatar asked Jan 25 '19 06:01

alezhka


People also ask

What is navigateUp?

navigateUp() Attempts to navigate up in the navigation hierarchy. @MainThread boolean. popBackStack()

What is NavController in Android?

NavController is the class which deals with the FragmentManager or FragmentTransaction. NavController manages application navigation with the NavHostFragment. Navigation flow and destination are determined by the navigation graph owned by the NavController class.


1 Answers

try this

val controller = Navigation.findNavController(view)
controller.popBackStack(R.id.id_of_fragment_which_you_want_to_skip, true)
like image 98
Deepak Rajput Avatar answered Sep 18 '22 18:09

Deepak Rajput