Search code examples
javaandroidactivity-finish

Why is finish() not quitting processing immediately?


Is there any particular situation when it is handy to not quit the Activity immediately after calling finish() ?

(in other way, why is this method not quitting the Activity immediately from design?)

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

UPDATE

When I say immediately, I mean, right in time you will call the finish() and of course, cleaning up with saving instance bundle, onStop and onDestroy methods doesn't count.

To see an example what am I talking about, here is the snippet

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

the question is, why is the code after condition finished as well before ending activity, and why the finish() call not stopping the processing immediately


Solution

  • Shouldn't you do a return to prevent the codes below to execute:

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