I\'m trying to change priority of main thread using android.os.Process.setThreadPriority()
. I have log messages before and after priority changing, here is code
You are using the wrong ThreadID for your check.
To get the correct id you have to use android.os.Process.myTid();
Fixed code:
package mypackage.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class TestActivity extends Activity {
public final String TAG="TestActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int tid=android.os.Process.myTid();
Log.d(TAG,"priority before change = " + android.os.Process.getThreadPriority(tid));
Log.d(TAG,"priority before change = "+Thread.currentThread().getPriority());
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
Log.d(TAG,"priority after change = " + android.os.Process.getThreadPriority(tid));
Log.d(TAG,"priority after change = " + Thread.currentThread().getPriority());
}
}
Log output:
priority before change = 0
priority before change = 5
priority after change = -4
priority after change = 5
For further reference:
http://developer.android.com/reference/android/os/Process.html#myTid()