Java – Why doesn’t finish() exit processing immediately?

Why doesn’t finish() exit processing immediately?… here is a solution to the problem.

Why doesn’t finish() exit processing immediately?

Is it convenient not to exit the activity immediately after calling finish()?

(In other words, why doesn’t this method immediately exit the activity from the design?) )

http://developer.android.com/reference/android/app/Activity.html#finish ()

Update

When I say immediately, I mean, you will call finish() at the right time, of course, cleaning up by saving the instance package, onStop, and onDestroy methods doesn’t count.

To see an example of what I’m talking about, here is the code fragment

onCreate(Bundle savedInstance){
     code executed
    if(somecondition){
        finish();
    }
     code which shouldn't be executed
}

The question is, why the code after the condition also finishes before ending the activity, and why the finish() call doesn’t stop processing immediately

Solution

Shouldn’t you make a return to prevent the following code from executing:

if(somecondition){
    finish();
    return;
}

Related Problems and Solutions