Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know activity has been finished?

I want to check to see if an activity is running or finished. Is there any method through which I can check the status of activity?

I found activity.isFinishing() but I am not sure about it.

like image 395
Connecting life with Android Avatar asked Jan 06 '12 11:01

Connecting life with Android


2 Answers

If you want to perform any step before Activity is going to become invisible.

Their are several choices here.

onDestroy() - for final cleanup.

isFinishing() - right after act.finish() is called it will return true.

onStop() - when the Activity is killed by framework process. (not destroyed)

onPause() - when the Activity is covered by any other Activity

onBackPressed() - capturing the event of hardware Back key triggered by user.

like image 192
Adil Soomro Avatar answered Nov 10 '22 19:11

Adil Soomro


Call isFinishing in the onPause method before the activity is destroyed:

@Override
protected void onPause() {
    super.onPause();
    if (isFinishing()) {
        // Here  you can be sure the Activity will be destroyed eventually
    }
}
like image 6
live-love Avatar answered Nov 10 '22 19:11

live-love