Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Single Instance of a Fragment

Tags:

android

Is there a way that when we use ft.addToBackStack(null); we only add a single instance to the BackStack? Adding multiple instances of the same fragment to the Back Stack creates a clutter when the user presses the Back Button?

like image 526
user1730789 Avatar asked Oct 22 '22 09:10

user1730789


1 Answers

You could try setting a string to the addToBackStack method. Ex

ft.addToBackStack("fragmentA");

Later then, if you are coing to insert that 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)

like image 196
Ordepi Avatar answered Oct 24 '22 17:10

Ordepi