Eli Elezra
Eli Elezra

Reputation: 65

Android system dialog popup cannot cancel

I am trying to close the system dialog but the dialog has only "ok" button and cannot cancelable on back button. I tried two ways. first in broadcast

public void onReceive(Context context, Intent intent) {
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.getApplicationContext().sendBroadcast(closeDialog);}

second

@Override
public void onWindowFocusChanged(boolean isTrue) {
    super.onWindowFocusChanged(isTrue);

    if (!isTrue){
        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);
    }
}

but no one works. Any help

enter image description here

Upvotes: 4

Views: 364

Answers (1)

Jerassi Ferrer
Jerassi Ferrer

Reputation: 284

You can use something like this:

.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog}});

Upvotes: 1

Related Questions