There are two activations - 1 and 2. From the first I turn to the second. I need that when I press the back button, I’m restarting Activation 1, but not from the saved state, but from the call to the onCreate method. That is, re-create activation 1.

How to create?

Thank you in advance.

  • one
    Isn't it easier to transfer the code from onCreate to onStart? - KoVadim

2 answers 2

Catch the onBackPressed event and start activating from it.

Intent i = new Intent( this , this.getClass() ); finish(); this.startActivity(i); 
  • I agree. But then you have to process onBackPressed in the first activation. Although in principle it is not critical)) - alexmx
  • And if the method finish () is used when switching to the second activity? - alexmx

You want strange. :) Most likely, you do not need to restart the activation 1. In addition, you negate the cached state. Try to transfer the code that should be executed each time you open the activation in the onStart method.

  • Well, not quite strange. In onCreate, I connect a custom view, and it starts a thread in which work with variables takes place. This is where the saved state (cache) is needed. But thanks anyway - alexmx
  • @alexmx, and you can not create a view in onCreate , and run the stream in onStart (and if necessary in onPause to stop it)? Probably, once the thread is launched from the view, it somehow updates the UI, and accordingly, it should start and stop along with the UI. - eigenein