user1730789
user1730789

Reputation: 5177

Android Single Instance of a Fragment

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?

Upvotes: 5

Views: 3672

Answers (1)

Ordepi
Ordepi

Reputation: 51

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)

Upvotes: 3

Related Questions