3

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.

Community
  • 1
  • 1
idolize
  • 6,455
  • 4
  • 24
  • 34
  • It's not the only way by the way. You may go with extending Binder. It's the only way if you need IPC across different applications. – stdout Oct 25 '15 at 09:29

1 Answers1

3

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

Restful API service

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.

Community
  • 1
  • 1
Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • UI thread just should do UI tasks. It shouldn't do other background tasks. –  Feb 13 '12 at 08:49