I a'm creating an Android application in which I'm managing some remainders. I want that when a certain event occur the dialog is show, And this is not a problem from me. But I want that if the user does not make any response within two minutes the dialog automatically dismiss. How can I implement this?
static AlertDialog alert = ....;
alert.show();
Runnable dismissRunner = new Runnable() {
public void run() {
if( alert != null )
alert.dismiss();
};
new Handler().postDelayed( dismissRunner, 120000 );
Don't forget to alert = null in your regular dialog dismiss code (i.e. button onClick).
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.game_message);
game_message = builder.create();
game_message.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
game_message.dismiss(); // when the task active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
}
}, 5000);
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