Inform Activity from a BroadcastReceiver ONLY if it is in the foreground

Posted by Zordid on Stack Overflow See other posts from Stack Overflow or by Zordid
Published on 2010-02-17T16:31:45Z Indexed on 2010/03/19 20:41 UTC
Read the original article Hit count: 589

Hi there!

Maybe it's easy, but I couldn't really figure this out right so far... I got a BroadcastReceiver waiting to get triggered by the AlarmMangager - this works fine.

Now: because the event, if it occurs, needs to refresh some elements on screen of the main Activity, I would like to send an Intent from that background BroadcastReceiver to my Activity - but only if it is currently in the foreground, aka active.

If it is not running or not visible, I don't care - and the last thing I want to do is start the Activity by my intent! I handle repainting of the views in my onResume method, so I don't care at all.

Any hints on how to do that? Thanks!

EDIT: my BroadcastReceiver is waiting for alarms that must be notified to the user. So, it must be there and declared in the manifest. The problem is: it will have to decide whether the mentioned Activity is currently up in front or not.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk