Update Running Activity from BroadcastReceiver?

by Cormac McCarty » Fri, 27 Feb 2009 01:48:33 GMT

Sponsored Links
 Hi all,

Is it possible to update a currently running activity from a BroadcastReceiver?

I have a BroadcastReceiver that's able to start an activity just fine
from its onReceive method.  But what if the activity is already
running?  How do I let it know that the BroadcastReceiver has some
more data for it?  Do I just start the activity again?  If so, would
that be a new instance of the activity?  What happens to the old one?
If it doesn't create a new instance, does onCreate get called again?
If not, how does the activity know that it's been hit again by the
BroadcastReceiver?  More importantly, in that case, how does the
activity get the data I attached to the intent in the


Update Running Activity from BroadcastReceiver?

by Cory » Fri, 27 Feb 2009 23:07:25 GMT

 I figured it out.

If you have the Activity register the BroadcastReceiver
programatically (ie, not in the manifest file), the Activity can have
a reference to the BroadcastReceiver.  Then you can give the Activity
a listener interface and register it with the BroadcastReceiver.  So
instead of having the BroadcastReceiver fire an Intent, it just calls
the callback on the Activity.  You may have to set up a Runnable and
call runOnUiThread() on the Activity, but it works just fine.



Sponsored Links

Other Threads

1. Mod: Gathering ID-Android with HTC Indonesia (Sabtu, 26 Juni 2010)

Wah om agus, berarti buat kita2 para pengguna HTC dapet freebies dung?
asikkkk, mbahnya htc android mustinya dapet extra bonus nie ^^

*harap2 ngayal

oys will always be Dreamrs

2010/6/18 Agus Hamonangan <id.andr...@gmail.com>


2. Background apps (Instant Messaging) being killed without user notification


I think this should be taken up with developers of these apps.

In particular, my recommendations to them would be:

- Use a startForeground / setForeground call to mark the service as being important to the user, do it only while the user is logged in. - Display a notification the phone's status bar, so the user knows if the service is still kicked out of memory. - Consider using AlarmManager to restart the service and re-login if there is an active logged in session. -- Kostya 23.06.2010 20:07, Simon Broenner :
1. Why am I, the user, not informed the the application has died, and hence, the connection has been lost? 2. Why are all the IM apps being killed, and not my other background apps? Sipdroid and Locale have NEVER been killed in this fashion.
-- Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com --

3. Background apps (Instant Messaging) being killed without user notification

4. Google support number for Droid's sent to Developers from Google?

5. Preorder samsung galaxy spica s

6. AlarmManager ceasing to function. Dropping single shot alarms.

7. Auto-completion/correction hints