My confusion has been due to the lack of appreciation that in spite of the 
fact that the server-obtained updates run asynchronously in a Thread 
started by the Service, the initial Service logic is part of the main 
thread which is shared with the Activities.

I had coded the Handler in one of the Activities.  I am moving the Handler 
into the Service.  This is the logical place for the code that fields 
asynchronous updates obtained from the remote location that must be 
interwoven into the functioning of the UI.  The placement satisfies two 
criteria:

   - It is started and ready to operate regardless of the state of the UI.
   - It lives in the UI thread so that no synchronization locking needs to 
   occur,
   
I simply need to provide a mechanism that enables the handler to determine 
which data structures are present and ready for update in the Activities at 
any given time.  This is accomplished by setting/resetting pointers to the 
Activies in onCreate/onDestroy. The communications thread simply needs to 
queue work to it.
Make sense?

On Friday, January 25, 2013 9:18:23 AM UTC-5, Bill Michaelson wrote:
>
> I have a Service that runs a distinct Thread to update a list based on 
> external events.  This list is simultaneously used to back ListViews in 
> associated Activities.  The Activities may also update the list based on UI 
> events.
>
> I need to provide appropriate synchronization.  I have coded a provision 
> to send update events from the Service to the Activity(ies) via Message 
> thru Handler.  Thus, I believe I can assure that the actual updates to the 
> data in the list occur in the UI thread which should work properly when the 
> Activity is running.
>
> But when the Activity is not running for whatever reason (not started, 
> destroyed, etc.), I need to have the Service update the list directly.  
> This is not a problem either; the Activity can find the revised list 
> content to create the ListView when it (re)starts.
>
> But my problem is that I want to find a reasonable mechanism for all 
> dynamic states, especially during transition, or in other words:
>
>    - signal to the Service that the Activity is running and should be 
>    used to process an update
>       - in such case assure that the update completes (i.e. that the 
>       Activity is not destroyed after the Message is passed, but before it is 
>       processed)
>    - otherwise signal that the Service must process the update in the 
>    absence of the Activity
>       - in such case assure that the Activity does not start and attempt 
>       to build a ListView prior to list content update completion by the 
> Service
>    
> I suspect this pattern of synchronization has been accomplished by 
> others.  Advice appreciated.
>
>
>

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


Reply via email to