O
O
orbit0702019-06-22 16:40:17
Android
orbit070, 2019-06-22 16:40:17

Why do buttons stop working when I call a dialog box?

Hello.
Before going back, I display a clarifying dialog box, if the user clicks "Yes", then only then do I return to the previous activity.

@Override
    public void onBackPressed() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder
            .setMessage(R.string.return_back_confirm)
            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    LoginCodeActivity.super.onBackPressed();
                }
            })
            .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            }).create().show();
    }

The problem is that if I switch to this activity again and try to go back again, the button stops being pressed and the console displays (but not with every click) "Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=1147649066, downTime=1147649066, deviceId=-1, source=0x101 }".
Also in the same activity there is one editText and if I click on it, the virtual keyboard does not appear, from which I conclude that not only the back button stops working, but also any clicks in general. If you remove the dialog box, then everything works.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sashulya, 2019-06-22
@Shikato

I think you should try adding the Activity end line to setPositiveButton

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question