HOw to resume Fragment from BackStack if exists
Hello I am using Fragment. I have created three instances of Fragment and
initialize them at the top of the class. I am adding fragment to an
activity like this:
Decalring and initializing:
Fragment A = new AFragment();
Fragment B = new BFragment();
Fragment C = new CFragment();
Replacing/Adding Fragment:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, A);
ft.addToBackStack(null);
ft.commit();
These snippets are working properly. And every Fragment is attached on
activity and saved to backStack successfully.
So when I launch A and then launch C and then launch B, the stack becomes
| |
|B|
|C|
|A|
___
And when I press back button, B is destroyed and C is resumed.
But when I again launch fragment A, instead of resuming from backstack, it
is added on the top of the backstack
| |
|A|
|C|
|A|
___
But I want to resume A and destroy all fragments upon it (if any).
Actaully I just like the deafult backStack behavior of activity. So how
can I do that?
Expected: (A should be resumed and top Fragments are to be destroyed)
| |
| |
| |
|A|
___
No comments:
Post a Comment