I have an Android app that runs a background service that collects sensor reading every second. I have found out that if there are other apps running, I do not collect my data every second (I have missing seconds). I assume that the OS does not give me sufficient CPU time.
Can I change my service's priority, among the running tasks, so it will get a sufficient amount of CPU and complete it p开发者_高级运维urpose?
(The service is called from an activity using StartService(mIntentService)
.)
The easiest would be to use startForeground() function that notifies the system to treat the service as a task user know about and would be disruptive to pause or terminate, so it will receive the same attention as the running apps. You need to provide Notification object so the user is informed about the running service.
精彩评论