Android close dialog after 5 seconds?

后端 未结 8 828
北海茫月
北海茫月 2020-12-05 02:00

I\'m working on an accesibility app. When the user wants to leave the app I show a dialog where he has to confirm he wants to leave, if he doesn\'t confirm after 5 seconds t

8条回答
  •  独厮守ぢ
    2020-12-05 02:51

    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);
    

    Reference : https://xjaphx.wordpress.com/2011/07/13/auto-close-dialog-after-a-specific-time/

提交回复
热议问题