0

In my android app I want to display an Alert dialog box for a limited time period. Which means If user doesn't reply to alert dialog box within limited time period , alert box must be closed. I searched on the Internet about this but could not find a way. Is anyone aware about how to do this ?

  • Try the accepted answer in this [SO post][1]. [1]: http://stackoverflow.com/questions/14445745/android-close-dialog-after-5-seconds – Illegal Argument Jun 07 '14 at 02:46

2 Answers2

1

Couple of options spring to mind You need to call the dialog dismiss() function right? so it's just a case of knowing when to call it.

Have a look at http://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor.html

and

http://developer.android.com/reference/java/util/Timer.html

The ScheduledThreadPoolExecutor in the first link looks like just the ticket for you.

The accepted answer here Where do I create and use ScheduledThreadPoolExecutor, TimerTask, or Handler? shows an example to how to use it. You would set it up in the onCreate of the Dialog class you are showing or at the time when you show the dialog in the calling class.

Community
  • 1
  • 1
jamesc
  • 12,423
  • 15
  • 74
  • 113
0

you can do like this

private final Runnable mDismissAction = new Runnable() {
    public void run() {
        dismissDialog();
    }
};

then you can dissmiss the dialog delay, use

handler.postDelayed(mDismissAction, delay);

when user click the dialog it will cancel the action, use

handler.removeCallbacks(mDissmissAction)
John Chen
  • 304
  • 3
  • 8