myPid和myTid以及myUid之间的区别

Nik*_*tel 3 android

::之间的区别

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
             //And 
int pid = android.os.Process.myTid();
android.os.Process.killProcess(pid);
             //And  
int pid = android.os.Process.myUid();
android.os.Process.killProcess(pid);
Run Code Online (Sandbox Code Playgroud)

spa*_*nia 5

只有第一个才能获得实际的进程ID并正确地终止进程.其他示例将失败,因为您将错误的进程ID传递给killProcess().

来自文档:

myPid() - 返回此进程的标识符,可以与killProcess(int)和sendSignal(int,int)一起使用.

myTid() - 返回调用线程的标识符,该标识符与setThreadPriority(int,int)一起使用.

myUid() - 返回此进程用户的标识符.

killProcess(int pid) - 使用给定的PID终止进程.

有关更多详细信息,请参阅文档. http://developer.android.com/reference/android/os/Process.html

以下是一些其他链接: