Log.i(TAG, "onCreate1: "+Process.myPid());
Log.i(TAG, "onCreate2: "+Process.myTid());
Log.i(TAG, "onCreate3: "+Process.myUid());
Log.i(TAG, "onCreate4: "+Thread.currentThread().getId());
Log.i(TAG, "onCreate5: "+getMainLooper().getThread().getId());
Log.i(TAG, "onCreate6: "+getTaskId());
Log.i(TAG, "onCreate7: "+getApplicationInfo().uid);
Log.i(TAG, "onCreate8: "+getApplicationInfo().processName);
从上到下分别为
1进程号
2当前线程号
3当前调用该进程的用户号
4当前线程ID
5主线程ID
6当前Activity所在栈的ID
7当前调用该应用程序的用户号(和3一样)
8当前调用该应用程序的进程名
(这里有个概念很重要,线程号和线程ID不一样)
查看打印结果
主线程中打印,符合预期
在子线程中打印结果
new Thread(new Runnable() {
@Override
public void run() {
Log.i(TAG, "onCreate1: "+Process.myPid());
Log.i(TAG, "onCreate2: "+Process.myTid());
Log.i(TAG, "onCreate3: "+Process.myUid());
Log.i(TAG, "onCreate4: "+Thread.currentThread().getId());
Log.i(TAG, "onCreate5: "+getMainLooper().getThread().getId());
Log.i(TAG, "onCreate6: "+getTaskId());
Log.i(TAG, "onCreate7: "+getApplicationInfo().uid);
Log.i(TAG, "onCreate8: "+getApplicationInfo().processName);
}
}).start();
符合预期结果