Search code examples
androidbroadcastreceiveralarmmanagerandroid-alertdialogalarm

AlarmManager opening (Alert)Dialog


My MainActivity sets an Alarm (or multiple Alarms). When the alarm goes of I want to show an AlertDialog that plays the alarm sound, shows info about the alarm and something like OK and delete, after that it should go back to my MainActivity.

If I read that right I cant create an AlertDialog from the BroadcastReceiver because its not an Activity.

So whats the best way to do this?

Do I have to open an Activity from the Receiver that then opens a Dialog?

EDIT: I just found out that I probably dont have to use the Receiver, I can just open my Main, get the extras from the Intent and then open the Dialog.

Is there a reason not to it like that?


Solution

  • You do need to use an activity to accomplish this. Do something like this:

    1. Use the receiver to start your Main activity.
    2. Use the Main activity to show an AlertDialog.