Deal of the Day

Home » Main » Manning Forums » 2010 » Android in Practice

Thread: Listing 5.9 The main Activity binding to the Service -- concurrency?

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Pages: 1 - Last Post: Feb 15, 2011 7:38 PM by: antipodeanvi Threads: [ Previous | Next ]
hanafey

Posts: 16
From: Wilmington DE
Registered: 1/11/10
Listing 5.9 The main Activity binding to the Service -- concurrency?
Posted: Jan 7, 2011 2:31 PM
  Click to reply to this thread Reply

In the onCreate method you call bindService which apparently asynchronously sets stockService in the ServiceConnection callback.

Immediately after the bind an AsyncTask is executed, and in the doInBackground callback you make use of stockService.

The question is, is it guaranteed that onServiceConnected will always be completed before the doInBackground is executed?

An alternative would be to put the async task inside the onServiceConnected method to ensure proper order of execution.

mgalpin

Posts: 2
From: San Jose
Registered: 1/30/11
Re: Listing 5.9 The main Activity binding to the Service -- concurrency?
Posted: Jan 30, 2011 7:27 PM   in response to: hanafey in response to: hanafey
  Click to reply to this thread Reply

That is a good catch. The much better way to do this is trigger the use of stockService to load the stocks member variable, during the onServiceConnected callback. I've updated the code and the manuscript to reflect this.

antipodeanvi

Posts: 5
From: Canada
Registered: 11/28/10
Re: Listing 5.9 The main Activity binding to the Service -- concurrency?
Posted: Feb 10, 2011 2:56 AM   in response to: hanafey in response to: hanafey
  Click to reply to this thread Reply

Is there any way with I could get an advanced peek at this code when the source is updated on this issue.

I am in trying get a widget (remote client) to bind to a service through the IPC mechanism. What is not clear to me is the role and configuration of the proxy packaging in a remote client. Using Set<> structure????? I would have thought the Activity manager would not mind handling either (Internal or external). An unit example of would be really helpful.

Also l would love to understand how the alarm manager wake lock mechanism works in its entirety. Your text is helpful. But I do not see the whole picture. How do you configure the broadcast receiver in the manifest? For example. Again, a simplified unit example of would be really helpful.

Thanks in advance.

Mat Hallam-Eames antipodeanvi

charlie.collins

Posts: 125
Registered: 3/8/07
Re: Listing 5.9 The main Activity binding to the Service -- concurrency?
Posted: Feb 15, 2011 6:38 PM   in response to: antipodeanvi in response to: antipodeanvi
  Click to reply to this thread Reply

I can't speak for Michael, but if the source has been updated it's probably been checked in (http://code.google.com/p/android-in-practice/source/browse/). Also, as for the manuscript, any recent changes should be in the new MEAP that went out today.

antipodeanvi

Posts: 5
From: Canada
Registered: 11/28/10
Re: Listing 5.9 The main Activity binding to the Service -- concurrency?
Posted: Feb 15, 2011 7:38 PM   in response to: charlie.collins in response to: charlie.collins
  Click to reply to this thread Reply

Hi Charlie,

Brillant....
Thanks for the link.

Mat Hallam-Eames

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor