Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether an activity is running or not [duplicate]

Possible Duplicate:
Check whether activity is active

I want to show a progress dialog on the screen if the activity is showing. But when the activity window is not showing, it will not do anything. Please suggest, how do I check whether my activity is showing or not?

like image 279
mudit Avatar asked Jul 15 '10 13:07

mudit


People also ask

How do I know if my android activity is recreated?

You can determine if the activity is finishing by user choice (user chooses to exit by pressing back for example) using isFinishing() in onDestroy . @Override protected void onDestroy() { super. onDestroy(); if (isFinishing()) { // wrap stuff up } else { //It's an orientation change. } }

How do you know if activity is visible?

In your finish() method, you want to use isActivityVisible() to check if the activity is visible or not. There you can also check if the user has selected an option or not.


1 Answers

Thanks for quick responses.. but i think i figured my answer. I try-catched the part where i was starting the progress dialog.

Sample code --

try {
        pd2.show();
    } catch (WindowManager.BadTokenException e) {
        // TODO: handle exception
    } catch (Exception e) {
        // TODO: handle exception
    }

So if my activity is in on the top, it will show the progress dialog, otherwise it will throw a BadTokenException which is handled using try catch block.

like image 125
mudit Avatar answered Sep 19 '22 11:09

mudit