0

i am creating material dialog inside the onReceive method.

@Override
public void onReceive(Context context, Intent intent)
{

new MaterialDialog.Builder(context)
                            .title(sender).content(m).positiveText("C").negativeText("Cl").onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                            copyToClipboard(m);
                        }
                    }).onNegative(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {

                        }
                    }).show();
 }

I am getting the below exception

 Caused by: com.afollestad.materialdialogs.MaterialDialog$DialogException: Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
user2269164
  • 1,095
  • 2
  • 15
  • 31

1 Answers1

0

You can not directly open a dialog from a Broadcast receiver as its a UI centric activity. The best way for you to do that would be to design a custom activity with a transparent background, register it as the Broadcast Receiver and then show the Alert dialog there.

Refer to Link

Kapil G
  • 4,081
  • 2
  • 20
  • 32