开发者

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

This question already has answers here: 开发者_StackOverflow Closed 10 years ago.

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?


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.


Read up on the Activity lifecycle. Specific methods get called based on your actvities current state, whether running, whether paused, killed, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜