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?
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.
精彩评论