views:

54

answers:

1

I am trying to create a Servicefor my application which will negotiate Bluetooth connections and data. I want this service's lifecycle to start and end with the Application, but still be able to have specific Activities listen for events that occur within this service (in addition an Activty should be able to call specific methods of the Service to write data or query connection state).

I started by creating AIDL interfaces for my callbacks and service, but I can't figure out exactly what I'm doing.

How is the best way to go about this? Thanks.

EDIT: To be clear, I do not specifically need (or want) more than one process for my application. Right now I don't have more than one; I'm just using AIDL because it is the only way I know of for a Service to communicate with an Activity.

+1  A: 

I posted an answer to a similar topic as this earlier today.

http://stackoverflow.com/questions/3197335/android-restful-api-service/3197456#3197456

I think the best way is to do an IntentService, and have your activity as a ResultReceiver, so when your service is done with some work it sends a message back to the activity.

BrennaSoft
One issue I notice with this right off the bat is that the IntentService does all of it's work in a new Thread... ideally I'd like to be able to run everything on the UI thread unless I specifically create a worker thread on my own.
mxrider