4

Difference between ::

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);
cpx
  • 17,009
  • 20
  • 87
  • 142
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133

1 Answers1

6

Only the first one will get the actual process Id and properly kill the process. The other examples will fail because you're passing the wrong process id to killProcess().

From the docs:

myPid() - Returns the identifier of this process, which can be used with killProcess(int) and sendSignal(int, int).

myTid() - Returns the identifier of the calling thread, which be used with setThreadPriority(int, int).

myUid() - Returns the identifier of this process's user.

killProcess(int pid) - Kill the process with the given PID.

See the docs for more details. http://developer.android.com/reference/android/os/Process.html

Here are some additional links:

Community
  • 1
  • 1
spatulamania
  • 6,613
  • 2
  • 30
  • 26
  • my problem is i have 10 activity and i have lots of resource in each activity so when application ahead one by one it will getting very slow so how can i kill particular activity process – Nikunj Patel Oct 15 '11 at 09:53
  • @Dr.nik Killing the process will stop your whole app and is normally discouraged on Android. If your app is using too many resources, I would suggest addressing the problem directly and trying to minimize your resource management. You can release (and reopen) data during OnPause and OnResume. Also, check out the tools in DDMS for memory tracking. – spatulamania Oct 15 '11 at 09:59
  • @Dr.nik I added links to the answer – spatulamania Oct 15 '11 at 10:21