3

I am having the issue regarding popup in broadcast receiver. I have implemented the popup by using activity with theme dialog. But When the app is in background and i received a broadcast. the popup window display above of the my opened activity no stand alone.

How to open the popup window only, not above my background activity.

Sandy
  • 6,285
  • 15
  • 65
  • 93
  • I have resolved this issue by using: Intent i = new Intent(context, NightClock.class); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_INSTANCE); context.startActivity(i); – Sandy Sep 21 '12 at 11:19

2 Answers2

2

Please check below link may be helpful to you

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

AlertDialog in BroadcastReceiver

Community
  • 1
  • 1
Nikhil
  • 16,194
  • 20
  • 64
  • 81
2

I guess.. in your onReceive method... you can write this

 Intent i = new Intent(context, NightClock.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i); 
success_anil
  • 3,659
  • 3
  • 27
  • 31
  • I am doing the same. But when the app is not running (not in the background) then it works fine. But if the app running in background then the popup comes but has background activity behind the Popup – Sandy Jun 22 '11 at 16:27
  • hmm In that case pls go through the link ...http://stackoverflow.com/questions/2314969/how-to-determine-if-one-of-my-activities-is-in-the-foreground ... I think it can give you a solution – success_anil Jun 22 '11 at 17:16
  • If kill the background activity or Make it foreground then it is not the solution:( – Sandy Jun 22 '11 at 17:48
  • I guess in that case ... if you can check whether your application is running or not ... then on the basis of that .. invoke an new activity from broadcast receiver. – success_anil Jun 23 '11 at 03:05
  • If application is running then how to invoke the new Activity(popup) and the backround activity will not come in the front?? – Sandy Jun 23 '11 at 05:06
  • umm.. probably we both are saying two different things. Alertnative to your approach of invoking a pop up just using Dialog theme on an activity, would be using AlertDialog class and showing alertdialog. – success_anil Jun 23 '11 at 05:51
  • Can not use dialog from broadcast receiver, only from actvity:( – Sandy Jun 23 '11 at 06:48
  • hmm invoke your activity first from broadcastreceiver... then in its oncreate method you can invoke the alert dialog if you want alert dialog to come at first place. – success_anil Jun 23 '11 at 08:27
  • Thats true, But Activity will also be available in background:( – Sandy Jun 23 '11 at 11:35
  • hmm never tried this... but if somehow we can determine that which activity of our application is in foreground we can invoke that particular activity from broadcast receiver using if else statements. And invoking that activity can invoke alert dialog. This could be a bit more programming effort. but remember I 'm assuming that our application is running. – success_anil Jun 23 '11 at 11:55
  • but invoking alert dialog from that activity is not the solution. I want only dialog without any activity. thats why i used Activity with theme dialog. – Sandy Jun 23 '11 at 15:49