Resume activity in Android

Sárzena picture Sárzena · Sep 13, 2012 · Viewed 40.6k times · Source

I have an app with 3 activities.

I have the main activity. This calls the second activity, which then calls the third activity. I want return to the main activity without entering the onCreate.

This is the code for the third activity:

startActivity(new Intent(TerceraActiviry.this, Main.class));

Answer

ThePCWizard picture ThePCWizard · Sep 13, 2012

If your Activity is still running, this code will bring it to the front without entering onCreate

Intent openMainActivity = new Intent(TerceraActiviry.this, Main.class);
openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(openMainActivity, 0);