开发者

Android - Service with Application lifecycle

开发者 https://www.devze.com 2023-01-06 20:34 出处:网络
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

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 crea开发者_Go百科ting 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号