If you want to mimic the "Home" button on specific Activities :
1st Method :
@Override
public void onBackPressed() {
Log.d("CDA", "onBackPressed Called");
Intent setIntent = new Intent(Intent.ACTION_MAIN);
setIntent.addCategory(Intent.CATEGORY_HOME);
setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(setIntent);
}
2nd Method :
@Override
public void onBackPressed() {
moveTaskToBack(true);
}
And if you want to move to the previous activity without destroying current :
@Override
public void onBackPressed() {
startActivity(new Intent(CurrentActivity.this, DestinationActivity.class);
}
And now from any activity if you want to open the activity which is in Background . I name CurrentActivity. you could call it form anywhere..like..it wil take that actvity and put it to top of stack . and open it where you left off.
Intent intent = new Intent(FromAnyActivity.this, CurrentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
Flags :
FLAG_ACTIVITY_REORDER_TO_FRONT
: To reorder the activity from stack
FLAG_ACTIVITY_CLEAR_TOP
: To remove all the activities from the top