Is WearableListenerService better than Service with Data and Message Listeners?

帅比萌擦擦* 提交于 2019-12-13 05:59:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!