为什么此警报对话框未在backPressed上显示?

  

这是我的onBackpressed():

@Override
public void onBackpressed() {
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainScreen.this);
        String checkInVal = preferences.getString("checkIn","");
        if (!PRE_USER_actIVE.equalsIgnoreCase("1")) {
            super.onBackpressed();
            finish();

        } else if (MainScreen.this.getSupportFragmentManager().findFragmentByTag("VOLUNTEERDetaILS") != null && checkInVal.equals("yes")) {
            popFragment();
        } else {
            if (Functions.iNumberOfLoadedFragments == 0) {
                String exitLog = "Exit Application",ok = "OK",cancel = "CANCEL";
                String sureLog = "Are you sure you want to exit  " + MainScreen.this.getResources().getString(R.string.app_name);
                if (EasyPreference.with(MainScreen.this,PRE_KEY)
                        .getString(PRE_USER_LANGUAGE,PRE_LANGUAGE_ENGLISH).equalsIgnoreCase(PRE_LANGUAGE_ASSEMESS)) {

                    exitLog = "প্ৰস্থান কৰক অ্যাপ্লিকেশন";
                    sureLog = "আপুনি Our SchoolZoneৰ পৰা প্ৰস্থান কৰিবলৈ নিশ্চিতনে";
                    ok = "স্বীকাৰ কৰক";
                    cancel = "বাতিল কৰক";
                } else if (EasyPreference.with(MainScreen.this,PRE_LANGUAGE_ENGLISH).equalsIgnoreCase(PRE_LANGUAGE_THI)) {

                    exitLog = "ออกจากแอพพลิเคชัน";
                    sureLog = "คุณแน่ใจหรือว่าต้องการออกจาก Our SchoolZone";
                    ok = "ตกลง";
                    cancel = "ยกเลิก";
                }
                new LovelyStandardDialog(MainScreen.this)
                        .setTopColor(Functions.getBackColor())
                        .setIcon(R.drawable.ic_info_outline_white_36dp)
                        .setTitle(exitLog)
                        .setMessage(sureLog)
                        .setPositiveButton(ok,new View.OnClicklistener() {
                            @Override
                            public void onClick(View v) {
                                MainScreen.super.onBackpressed();
                            }
                        })
                        .setNegativeButton(cancel,new View.OnClicklistener() {
                            @Override
                            public void onClick(View v) {

                            }
                        })
                        .show();

            } else if (Functions.iNumberOfLoadedFragments > 0) {
                Functions.iNumberOfLoadedFragments--;
                super.onBackpressed();
            }
        }
}
  

需要在此活动按下的后退按钮中显示ALertDialog   相反,该应用仅退出启动器。

     

可能出现的问题,请回复您的宝贵建议。谢谢

yhfhr8100 回答:为什么此警报对话框未在backPressed上显示?

使用以下代码: AlertDialog,退出应用

@Override
public void onBackPressed() {
    new AlertDialog.Builder(this)
            .setMessage("Are you sure you want to EXIT ?")
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog,int which) {
                    moveTaskToBack(true);
                    finish();

                }

            })
            .setNegativeButton("No",null)
            .show();
}

upvote(如果发现有用),以便其他人可以得到答案

本文链接:https://www.f2er.com/3119855.html

大家都在问