首页 > 代码库 > Android 进程

Android 进程

获取正在运行的进程列表:

代码

 ActivityManager mActivityManager = (ActivityManager) this .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> list = mActivityManager .getRunningAppProcesses();
        for (int j = 0; j < list.size(); j++) {
            Log.i("tag", list.get(j).processName);
        }

通过Process.myPid()和 RunningAppProcessInfo来取得当前的进程名:

String getCurProcessName(Context context) {

 int pid = android.os.Process.myPid();

 ActivityManager mActivityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE);

 for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager .getRunningAppProcesses()) {

  if (appProcess.pid == pid) {

   return appProcess.processName;

  }

 }

 return null;

}

Android 进程