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:
- use the HashKey to get a reference to the object instance.
- Use a memory analyzer tool (such as Java Monitor or JMAP) to see the objects instantiated in memory
- Use JDK to get a Java Heap dump and analyse the results.
- 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;
}
精彩评论