get amount of running processes - Android Android OS

Android examples for Android OS:Process

Description

get amount of running processes

Demo Code


//package com.java2s;
import java.util.List;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;

public class Main {
    private static ActivityManager am = null;

    /**//  w  w  w  .  j  ava 2 s . c o m
     * get amount of running processes
     * @param context context
     * @return amount of running process
     */
    public static int getRunningProcessAmount(Context context) {
        return getRunningProcesses(context).size();
    }

    /**
     * get running processes
     * @return list of running process
     */
    public static List<RunningAppProcessInfo> getRunningProcesses(
            Context context) {
        if (am == null) {
            am = (ActivityManager) context
                    .getSystemService(Context.ACTIVITY_SERVICE);
        }
        return am.getRunningAppProcesses();
    }
}

Related Tutorials