4

I'm building an android application with BroadcastReceiver and I want to show a dialog when onReceive starts. I want to show the dialog on the phone (show the user a dialog no matter where he is, like the whatsapp dialog when you get a message).

How I can do that?

Thanks!

Claudio
  • 2,191
  • 24
  • 49
user1840196
  • 53
  • 1
  • 1
  • 6

1 Answers1

5

If you want to show a dialog from inside your onReceive of the BroadcastReceiver, inside your broadcast receiver you may start a transparent activity with an alert dialog and NEVER called setContentView(). The activity will have an transparent view and only the alert dialog will show. Source: show an alert dialog in broadcast receiver after a system reboot

There are many similar posts which talk about this topic. See below questions for code samples and other reviews on the same:

  1. AlertDialog from within BroadcastReceiver?? Can it be done?

  2. How to raise an alert dialog from BroadcastReceiver class?

  3. How can I display a dialog from an Android broadcast receiver?

  4. How to setup Alertbox from BroadcastReceiver

Hope this will help.

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • I have problem with that, i have 2 activities, and i start the second acticity (the new and not the main), but it's start me the main activity and i dont know why, to the new acticity have class and xml file, and it's work, but i dont know why the recevice start hte main... i do this: Intent i = new Intent(context, BTNotifierWarning.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); | but BTNotifierWarning is'nt the main acticity... – user1840196 Jul 28 '13 at 08:02
  • Hey. I am sorry for my previous comment. I thought that its related to this question, so I asked you to edit it. It would be better if you keep the questions separate. Ask a new question for the new problem that you mentioned in the comment. Remove that piece of code from this question. It might confuse others. – Shobhit Puri Jul 28 '13 at 08:17
  • Ok, thanks! this is the new question: http://stackoverflow.com/questions/17906466/how-to-load-activity-from-broadcastreceiver-onreceive – user1840196 Jul 28 '13 at 08:33