Assume you have two Activities A and B. You navigate from A to B. A goes to background .
B is put on back stack and B takes focus. When you click back button activity B pops out of back stack. Activity A is resumed.
Note: Multiple tasks can be held in the background at once. However, if the user is running many background tasks at the same time, the system might begin destroying background activities in order to recover memory, causing the activity states to be lost. See the following section about Activity state.
http://developer.android.com/training/basics/activity-lifecycle/starting.html. Activity once destroyed has to be recreated. Activity is destoyed and recreated when the screen orientation changes.
http://developer.android.com/training/basics/activity-lifecycle/starting.html.
http://developer.android.com/guide/components/tasks-and-back-stack.html. You should have a look at how back stack works.
In your case finish should work for you (by pressing the back button).
Note :The system calls onDestroy() after it has already called onPause() and onStop() in all situations except one: when you call finish() from within the onCreate() method.
Suppose you have a third activity C and you want to go to Activity A .
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
public void onBackPressed() {
Intent myIntent = new Intent(ActivityC.this, MainActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// clear back stack
startActivity(myIntent);
finish();
return;
}