如何确定流程com.android.browser
是否正在运行?
答案 0 :(得分:1)
使用ActivityManager#getRunningAppProcesses()
。它将返回List
RunningAppProcessInfo
。您可以查看列表中每个元素的processName
,看看它是否是您正在寻找的过程。
boolean isNamedProcessRunning(String processName)
{
if (processName == null) return false;
ActivityManager manager =
(ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningProcessInfo> processes = manager.getRunningAppProcesses();
for (RunningProcessInfo process : processes)
{
if (processName.equals(process.processName)))
{
return true;
}
}
return false;
}
答案 1 :(得分:0)
我能想到以下几点:
PS。有点奇怪的问题。你能告诉我你为什么需要这个吗?
答案 2 :(得分:0)
这是工作代码:
public static boolean isThisProcessRunning(Context context, String processName) {
if (processName == null){
return false;
}
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
for (RunningAppProcessInfo process : processes) {
if (processName.equals(process.processName)) {
return true;
}
}
return false;
}