gogoWebsite

Summary of common methods for obtaining current process and thread IDs on Android

Updated to 2 hours ago

Common ways to obtain threads and processes:

  1. Get the current process ID: ();
  2. Get the user ID of the current process:();
  3. Get the current thread ID (1): ().getId();
  4. Get the current thread ID (2): ();
  5. Get the application main thread ID: ().getThread().getId());

Common ways to set thread priority

  1. Set the current thread priority: setThreadPriority(int priority);
  2. Set the specified thread priority: setThreadPriority(int tid,int priority);
  3. Get the specified thread priority: getThreadPriority(int tid);

Manage specified processes

  1. Kill the specified process: killProcess(int pid);
  2. Send a signal to the specified process: sendSignal(int pid,int singal);

In Android app development, it is often necessary to determine whether the current thread is in the main thread. There are mainly the following ways:

  1. Use the Looper class to judge:

() != ()

  1. By viewing the current thread of the Thread class:

() == ().getThread()