Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Priority of IntentService in Android

I was wondering if it is possible to set the priority of an IntentService like you can with a Thread. So far I have not found anything.

like image 491
smith324 Avatar asked Sep 01 '10 20:09

smith324


2 Answers

You can set Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND) in the onHandleIntent() method of your intent service.

The solution by CommonsWare also works. This one is simpler, though.

like image 71
espinchi Avatar answered Oct 05 '22 12:10

espinchi


The HandlerThread that IntentService uses is not exposed to the SDK. It is set to Process.THREAD_PRIORITY_DEFAULT as a priority.

Note that IntentService is 143 lines of code, including whitespace and comments, so you might consider just cloning it to have one with the priority you seek.

like image 31
CommonsWare Avatar answered Oct 05 '22 12:10

CommonsWare