After the application is minimized, after some time (or if you open a lot of things) I launch the application, it activates, which in the top task and starts executing the code from onCreate (), but receives activation data from the lower activations, they are actually null and the application drops works! How to make it so that when idle in the background, the application was launched from the root activation, but with a short folding normally opened!

  • onPause, onResume? - Chad
  • What are you offering? - katso
  • 2
    save this data in preferences - Gorets
  • I propose to override these methods and save there data that will be needed for recovery - Chad
  • @ Chad, I do not need to save and restore! Task should be cleared when idle and the root activity is loaded, and the last one is loaded! - katso


2 answers 2

Hit the activation when onPause?

function void onPause(...) { finish(); } 
  • This is obvious! But if the user minimizes the application, the activity will collapse! The question was: "How to make it so that when idle in the background, the application was launched from the root activity, but when it was closed for a short time, it would open normally!" In theory, the application should not behave this way, by default the task should be cleared! Maybe I namudil somewhere! - katso
  • Well, then get on then onDestroy? - Chad
  • @Chad, it seems meaningless to me to destroy activations by redefining the method of activating destruction! Although who knows, I'll try! - katso
  • @katso, well, you must also check in addition - that you didn’t call the destruction, but the system. But in general, probably another solution could be to hang on onResume checking - if the data is killed - then finish () - Chad
  • Although probably yes, hang on onStop and not on onDestroy. In any case, you need to prescribe the logic of rollback to the main activation. And do not hope for magic - Chad

Found a solution, I do not know how safe and correct it is.

after

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 

put in

  if (savedInstanceState != null) { finish(); } 

And now everything works as it should.