A single instance of Android fragment

Is there any way that when using ft.addToBackStack(null); Are we adding only one instance to BackStack? Adding multiple instances of the same fragment to the Back Stack creates a mess when the user clicks the back button?

+4
source share
1 answer

You can try setting the string to the addToBackStack method. Ex

 ft.addToBackStack("fragmentA"); 

Later, if you want to insert the same fragment again. You do this before adding it to the layout.

 getFragmentManager().popBackStack("fragmentA", FragmentManager.POP_BACK_STACK_INCLUSIVE); 

http://developer.android.com/reference/android/app/FragmentManager.html#popBackStack (java.lang.String, int)

+3
source

Source: https://habr.com/ru/post/1481773/


All Articles