Hi,

I'm trying to implement a service that is started by an activity.  When the 
service starts off, it spawns a worker thread that makes a socket 
connection.  If the socket connection fails, I want to stop the service. 
 All this is working fine, but I don't have a good handle of how to 
indicate to the activity that the service could not start successfully, and 
has, therefore, turned itself off.

One way to do this is to communicate via a listener that is attached into 
the service in the onServiceConnected() connection callback.  The problem 
with this approach is that, depending on when the worker thread notices the 
error, the onServiceConnected() may or may not have been called, and 
therefore the listener may or may not have been attached by the time the 
worker thread decides to shut down the service.

I was hoping that onServiceDisconnected() would be called, but that is only 
called in case of an unexpected crash, and isn't really useful when the 
service and activity exist in the same process.

My question is, what is the best way to approach something like this?  It 
seems silly to me that even though the activity and service exist in the 
same process, the activity cannot figure out the state of the service that 
easily.  I _can_ use a static state variable within the service, but that 
still doesn't allow the activity to be notified of the event.

Thanks!

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