How to run accelerometer on background?

可紊 提交于 2019-12-11 10:35:20

问题


I need to implement accelerometer running on background service on Android. The thread has to communicate both way and fire event based on accelerometer data. The service has to run indefinitely and in case that OS kills service, it restarts from previous state. I did some research and I am not sure whether to use Bound Service or Out of process Service. Is it possible to implement this task? Which type of service works for this problem?


回答1:


Is it possible to implement this task? Which type of service works for this problem?

You will need partial wake lock to prevent the service from being stopped.

Then you can use certain service like Foreground Service as @SushiHangover suggested to track accelerometer data and fire event when necessary.



来源:https://stackoverflow.com/questions/47315432/how-to-run-accelerometer-on-background

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