开发者

Determine if process com.android.browser is running

How can I determine if the proces开发者_C百科s com.android.browser is running?


Use ActivityManager#getRunningAppProcesses(). it will return a List of RunningAppProcessInfo. You can check the processName of each element in the list to see if it's the process you're looking for.

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;
}


I can think of the following:

  1. use the HashKey to get a reference to the object instance.
  2. Use a memory analyzer tool (such as Java Monitor or JMAP) to see the objects instantiated in memory
  3. Use JDK to get a Java Heap dump and analyse the results.
  4. Add something in your own application to log whenever an object is instantiated or destroyed.

PS. Kind of strange question. Could you tell more on why you need this?


Here is working code:

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜