I will not follow the sample code in satur9nine's answer as of 2011-Dec-22.
Thread.MIN_PRIOROTY maps to android.os.Process.THREAD_PRIORITY_LOWEST. Quote :
Lowest thread priority available. Only for those who really really don't want to run if something else happens.
I would at least use android.os.Process.THREAD_PRIORITY_BACKGROUND, for example:
HandlerThread bgThread = new HandlerThread("handler name"); Process.setThreadPriority(bgThread.getThreadId(), Process.THREAD_PRIORITY_BACKGROUND); bgThread.start(); mBgHandler = new Handler(bgThread.getLooper());
This prioritizes the default Android background image for the stream.
Currently, the priority threads Process.THREAD_PRIORITY_BACKGROUND and below share an artificially limited amount of processor time using the Linux group, see, for example, here . If the background task is not just waiting for I / O, but also performing real calculations, I would consider increasing my priority with android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE, which (currently) moves it from the background group, but still not poses threats to the user interface and in real time.
Update:. Satur9nine's answer was reversed in 2013-Jan-08 so as not to set the lowest priority. HandlerThread now implies android.os.Process.THREAD_PRIORITY_BACKGROUND priority. This means that now it gets the priority of the background task by default, but it is still limited by consuming an artificial maximum of 10% of the processorโs time, along with all other background tasks that may exist. If this is undesirable, use my code above, for example. from
Process.setThreadPriority(bgThread.getThreadId(), Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE);
to remove the background stream from the group.
class stacker Jan 08 '13 at 12:18 2013-01-08 12:18
source share