I have 2 activities
intent = new Intent(this, MainActivity.class);
Do not restart the main activity. Use
finish() instead. That takes you back to the original
MainActivity instead of creating a new one. This is the same behavior you get from the back button.
See Tasks and Back Stack for a more in-depth view of the back stack.