问题
I have connected my application to Android Wear's Wearable Data Layer with a service that implements DataApi.DataListener, and MessageApi.MessageListener. This service allows me bind to my activities (WearableListenerService does not) and exchange data and messages between the apps perfectly fine. Recently I noticed that my service was getting terminated by the system which leads me to my questions:
1. Is WearableListenerService better than the above setup in that it is less likely to be terminated by the system under load?
2. When does a WearableListenerService get terminated by the sytstem if at all?
**I plan to have this as a long running service waiting for events to be triggered from an Android smartwatch
As an interesting note, I found an issue on the AOSP issue tracker covering how long the wearable service will last and it is marked as obsolete without an answer: See this issue
回答1:
Your implementation of WearableListenerService will be invoked by the system when there is a message, data layer changes, etc for your app and it terminates relatively quickly when its job is done (shortly after you leave the scope) so the main advantage of using that is you don't have to have a long-running background service (which kills resources and battery) to listen to possible incoming data for your app.
来源:https://stackoverflow.com/questions/31840366/is-wearablelistenerservice-better-than-service-with-data-and-message-listeners