Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 779
Marek Sebera Avatar asked Oct 16 '25 13:10

Marek Sebera


2 Answers

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

if(somecondition){
    finish();
    return;
}
like image 83
evanwong Avatar answered Oct 18 '25 02:10

evanwong


Imagine you have a thread_0 with a loop handling all the events.

Calling finish adds a new event, but the activity isn't killed until thread_0 handles the event.

like image 45
vieux Avatar answered Oct 18 '25 02:10

vieux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!