I want to destroy the current page when the back button is pressed, but my back button doesn't work when showing an AlertDialog.  

I already implemented onBackPressed like below, but it still doesn't work.

```
 private void showPopupSubscribe() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View dialogView = getLayoutInflater().inflate(R.layout.paket_subscribe, null);
    builder.setView(dialogView);
    builder.setCancelable(false);
    builder.setIcon(R.drawable.logo_1);
    builder.setTitle(R.string.confirm);
    final RadioGroup radioGroup = dialogView.findViewById(R.id.rgSubscribe);

    builder.setPositiveButton("Next", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            pd.show();
            int selected = radioGroup.getCheckedRadioButtonId();
            if (selected == R.id.rbMonthly) {
                smsCode = "aa";
            } else if (selected == R.id.rbTwoWeeks) {
                smsCode = "bb";
            } else if (selected == R.id.rbWeekly) {
                smsCode = "cc";
            } else if (selected == R.id.rbTwoDays) {
                smsCode = "dd";
            }
            reqWebCharging(smsCode);
            dialog.dismiss();
        }
    });

    dialog = builder.create();
    dialog.show();
}

@Override
public void onBackPressed() {
    super.onBackPressed();

    if (dialog.isShowing()) {
        finish();
    }
}

```