What you learn: You will learn how to change the Thread-Priority of your Activity (Process). Possible field of use: Audio-Applications needing High-Priority Threads.
Difficulty: 2 of 5
What it will look like:
[align=center]Nothing to see here...[/align]
Description:
0.) To raise the Thread-Priority of our Threads in our Activity we need a 'uses-permission' in the AndroidManifest.xml to do so:
Using xml Syntax Highlighting
- <uses-permission id="android.permission.RAISED_THREAD_PRIORITY"/>
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
So now you can change/raise the Priority of any Thread within your Activity using the following code:
Using java Syntax Highlighting
- import android.os.Process;
- // ...
- // -----------------------------------
- // Set the priority of the calling thread, based on Linux priorities:
- // -----------------------------------
- // Changes the Priority of the calling Thread!
- Process.setThreadPriority(12);
- // Changes the Priority of passed Thread (first param)
- Process.setThreadPriority(Process.myTid(), 12);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
[align=center]:warning: Where the range is from -20 (high) to +19 (low). Choose not too high
[/align]
Using java Syntax Highlighting
- // Lower is 'more impotant'
- Process.THREAD_PRIORITY_LOWEST = 19
- Process.THREAD_PRIORITY_BACKGROUND = 5
- Process.THREAD_PRIORITY_DEFAULT = 0
- Process.THREAD_PRIORITY_FOREGROUND = -5
- Process.THREAD_PRIORITY_DISPLAY = -10
- Process.THREAD_PRIORITY_URGENT_DISPLAY = -15
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
More detailed explanation on which Priority to use when.
Regards,
plusminus





