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?
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. } }
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With