Android close dialog after 5 seconds?

后端 未结 8 836
北海茫月
北海茫月 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:44

    Use CountDownTimer to achieve.

          final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
                .setTitle("Leaving launcher").setMessage(
                        "Are you sure you want to leave the launcher?");
           dialog.setPositiveButton("Confirm",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                         exitLauncher();
    
                    }
                });
        final AlertDialog alert = dialog.create();
        alert.show();
    
        new CountDownTimer(5000, 1000) {
    
            @Override
            public void onTick(long millisUntilFinished) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onFinish() {
                // TODO Auto-generated method stub
    
                alert.dismiss();
            }
        }.start();
    

提交回复
热议问题