警报对话框在用户看到任何内容之前消失

And*_*per 0 android timer listener period android-alertdialog

@Override
    public void onBackPressed() {
    // TODO Auto-generated method stub            
      PopIt("Exit Application", "Are you sure you want to exit?");

        super.onBackPressed();

    }

    public void PopIt( String title, String message ){
            new AlertDialog.Builder(this)
            .setTitle( title )
            .setMessage( message )
            .setPositiveButton("YES", new OnClickListener() 
            {
                public void onClick(DialogInterface arg0, int arg1) {
                    //do stuff onclick of YES
                    finish();
                }
            }).setNegativeButton("NO", new OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    //do stuff onclick of CANCEL
                    Toast.makeText(getBaseContext(), "You touched CANCEL", Toast.LENGTH_SHORT).show();
                }
            }).show();
        }
Run Code Online (Sandbox Code Playgroud)

这个警报对话框速度太快,我无法阅读或点击它!这是为什么 ?

ƒer*_*lle 5

问题是你在调用super.onBackPressed()之前扔掉了Popit.删除它 :)