Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control service priority

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 purpose?

(The service is called from an activity using StartService(mIntentService).)

like image 981
bahar_p Avatar asked Jul 09 '26 21:07

bahar_p


1 Answers

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.

like image 98
jJ' Avatar answered Jul 11 '26 10:07

jJ'