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
BroadcastReceiver?

--~--~---------~--~----~------------~-------~--~----~



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.

-Cormac



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Sensor listeners - threads and responsiveness

hi,
I have two questions about sensor listeners

1. from which thread are sensor values updated and should this be
synchronized? can sensor's listener callback be a good place to call
custom's view onDraw method? as this should be done from different
thread. I cant find anything about it. In another words my problem is
that I want to listen to sensors change and draw something on view
surface but I dont know which thread (the main thread of the
application??) is updating sensor's state

2. If I register sensor listener with SENSOR_DELAY_FASTEST my
application is not responsive at all! Raw application with TextView
only is not reacting to go back or home button!
How should I deal with this or am I doing something wrong?

thanks for help

-- 

2. Change background after an Orientation change

Sure, you have to create a different layout file for the landscape
mode with a different background image in the layout-land folder.

Try searching for it in the docs and you will get an idea on what and
how to do it.
http://tech-droid.blogspot.com/2009/10/orientation-independent-applications.html

Thanks and Regards,
Kumar Bibek
http://tech-droid.blogspot.com




-- 

3. problem with httpclient and self signed certificates

4. problem with httpclient and self signed certificates

5. FROYO build

6. QuickActions like the Twitter for Android app

7. Launcher don't work when overlaped by transparent NOT_TOUCH_MODAL Activity.