I have a progress dialog which is shown during some running action.
If the action hasn’t executed for a given time, I want to dismiss the dialog and the action. How do I implement this?
I currently have these two methods, which stop and start my async action and dialog:
private void startAction()
{
if (!actionStarted) {
showDialog(DIALOG_ACTION);
runMyAsyncTask();
actionStarted = true;
}
}
private void stopAction()
{
if (actionStarted) {
stopMyAsyncTask();
actionStarted = false;
dismissDialog(DIALOG_ACTION);
}
}
i.e. I want to do something like this when the time is out:
onTimesOut()
{
stopAction();
doSomeOtherThing();
}
You can make a simple timer: