Android - Simulate Back Button Android - Simulate Back Button android android

Android - Simulate Back Button


Calling finish() from the activity you want to end should take care of this.

Edit many years later: This still works, but it's a bit of a heavy-handed approach. When I originally posted this, Fragments didn't exist, and (as several commenters have pointed out) this doesn't work quite the same way when there are Fragments involved. There are better approaches now if you're using Fragments.


Just for record: The described method doesn't do the same as the back button does in some cases, but you can call

this.onBackPressed();

or

getActivity().onBackPressed();

if you are in a fragment to achieve exaclty the same behaviour.


when using fragments:

getFragmentManager().popBackStack();

or

getSupportFragmentManager().popBackStack();

if you are using android.support.v4.app package