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. ImageView with zoom, or just use WebView somehow?

Hi,

I'd like to display a single image from the web. It'd be nice if it
could be zoomable and pan-able. I was thinking of just using a WebView
to do this:

   webView = new WebView();
   webView.loadUrl("mysite.com/mypicture.jpg");

but I can't force the webview to center the picture etc.

Is there any other built in image viewer widget in android? I looked
at Gallery and ImageSwitcher but these don't let you zoom either.

Thanks

-- 

2. tanya cymogen 4.2.5 unt dream, bagus n stabil udaan???? ada yg uda coba?? share :)

mau tanya nih
ada yg uda coba g CM 4.2.5 unt dream?? gimana oke g???

klo ada yg uda nyoba tolong dong bantu untuk linknya
maklum baru pertama mau ngeroot nih
langkah2 yg mudah gimana ya (klo bisa bhs indo aja :))
apa aja yg diperlukan Tq
--~--~---------~--~----~------------~-------~--~----~
=========================
Google Groups "Indonesian Android Community [id-android]" group.

To post to this group, send email to id-android@googlegroups.com

To request to subscribe to this group:

Click  

3. tanya pengguna htc dream

4. Fwd: [Mobile-App-Developers] Google Mobile Blog

5. how to get domain name

6. DROID so buggy (OpenGL) -- and work around

7. how can I target api 1.6, but use packages from 2.0 (and safely)