user3661749
user3661749

Reputation: 1

how to go from one fragment to previously opened fragment using back stack

For example I want to go back to home before exiting my app.

This is my code....

case 0: frag = new Home();

case 1: frag = new AboutUs();

transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragemnt_container, frag);
transaction.commit();

If i click on Home button in navigation drawer and then click on aboutus button, and When i press back button on my phone i want to go from aboutus fragment to home fragment without exiting my app.

Any Help would be appreciated.

Thank you.

Upvotes: 0

Views: 44

Answers (1)

Emmanuel
Emmanuel

Reputation: 13223

You need to add the FragmentTransaction to the backstack. It is as simple as calling addToBackStack() before you commit the transaction.

Upvotes: 1

Related Questions