问题
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