Completion of non-termination of action code execution

I tried the following code

Log.d("t20", "First here");
startActivity(new Intent(this, AnotherActivity.class));     
finish();
Log.d("t20", "Then Here");

log output:

First here
Then Here

Why is the second journal message printed? Execution must be stopped on finsh(), right?

+4
source share
3 answers

No, the finish is not interrupted. The function will continue, and when it returns to Looper inside the Android framework that starts the event loop, it will start the de-initialization sequence (by calling onPause, onStop and onDestroy).

+5
source

finish() , "". , . , finish() Activity, Activity.isFinishing().

:

Check to see whether this activity is in the process of finishing, either because you
called finish() on it or someone else has requested that it finished. 

, :

Log.d("t20", "First here");
startActivity(new Intent(this, AnotherActivity.class));     
finish();
if (!isFinishing()) {
    Log.d("t20", "Then Here");
}
+4

finish() onDestroy(), :

  • , .
  • , .
  • In addition, onDestroy () is not a destructor. This does not actually destroy the object. This is simply a method that is called based on a specific state. So your instance is still alive and very good * after the onDestroy () superclass starts and returns. Android supports processes in case the user wants to restart the application, this speeds up the launch phase. The process will not do anything, and if the memory needs to be fixed, the process will be killed
+1
source

Source: https://habr.com/ru/post/1532608/


All Articles