How to go back to an Activity already created without recreating it again?

Asked

Viewed 2,195 times

0

I know that activities on Android are stored as a stack. But I needed to use the button onBackPressed() and go back there are 2 screens behind without recreating this screen. With the Intent it recreates the screen. Is it possible to go back 2 screens without recreating the Activity? Thank you in advance!

1 answer

3


You can use the constants that class Intent offers to developers.

Example:

Intent it = new Intent(Class1.this, Class2.class);
it.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(it);

Intent.FLAG_ACTIVITY_NO_HISTORY:

If set, the new Activity is not Kept in the history stack.

Português:

If set, the new Activity is not kept in battery history.

Documentation and other constants:

http://developer.android.com/reference/android/content/Intent.html#constants

Browser other questions tagged

You are not signed in. Login or sign up in order to post.