On Fri, Mar 9, 2012 at 11:28 AM, Ted Scott <t...@hootinholler.com> wrote:
> I have a service that obtains and stores sample data from a web service. It
> is triggered by alarms, gets a sample which may or may not be new, stores it
> in my DB.
>
> At that point, if a new sample was added, and the activity that lists the
> samples is active, I want to notify it to refresh the cursor to include the
> new sample. If the activity isn't running, I don't care because it will be
> fine when it launches. If I set up a receiver and send a broadcast won't the
> broadcast cause it to launch if the activity isn't running? That is behavior
> that I don't want.

Use an ordered broadcast to notify your foreground activity, and
possibly display a Notification if the activity is not in the
foreground:

http://commonsware.com/blog/2010/08/11/activity-notification-ordered-broadcast.html

Here is a sample demonstrating this:

https://github.com/commonsguy/cw-advandroid/tree/master/Broadcast/Ordered

Or, have your activity get its data from the service via a
ContentProvider, and use a ContentObserver (which happens
automagically if you are using a CursorLoader).

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 4.0 Programming Books: http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to