Skip to content Skip to sidebar Skip to footer

How To Return To Previous Fragment Activity

Three fragment activities: MainFragmentActivity, Reports and ReportsType. Reports is calling ReportsType. There is a back button in ReportsType to go back with the following code:

Solution 1:

There's no concept of calling finish() on Fragment. Instead, you should keep stack of fragments when performing transactions. For example:

ft.addToBackStack(null);   // ft is FragmentTransaction

So, when you press back-key, the current activity (which holds multiple fragments) will load previous fragment rather than finishing itself.

Solution 2:

Try this..

Intent i=newIntent(this,MainFragmentActivity.class)
startActivity(i);
finish();

Intent i=newIntent(this,Reports.class)
startActivity(i);
finish();

Intent i=newIntent(this,ReportsType.class)
startActivity(i);
finish();

When you call new Activity write finish() in last

Post a Comment for "How To Return To Previous Fragment Activity"