How to get back to an already created activity without re-creating it?

0

I know that activities on Android are stored as a stack. But I needed to use the onBackPressed() button and go back 2 screens ago without recreating this screen. With the intent it re-creates the screen. Is it possible to go back 2 screens without re-creating the activity? Thank you in advance!

    
asked by anonymous 28.09.2015 / 20:50

1 answer

3

You can use the constants that the Intent class 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.

English:

  

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

Documentation and other constants:

link

    
28.09.2015 / 21:14