is Running Process - Android Android OS

Android examples for Android OS:Process

Description

is Running Process

Demo Code


//package com.java2s;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;

import android.content.Context;

import android.text.TextUtils;
import java.util.List;

public class Main {

    public static boolean isRunningProcess(Context context,
            String processName) {
        ActivityManager manager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        int pid = android.os.Process.myPid();
        List<RunningAppProcessInfo> processInfoList = manager
                .getRunningAppProcesses();
        if (processInfoList != null && !processInfoList.isEmpty()) {
            for (RunningAppProcessInfo processInfo : processInfoList) {
                if (processInfo != null
                        && processInfo.pid == pid
                        && TextUtils.equals(processName,
                                processInfo.processName)) {
                    return true;
                }//from www  .  j  a  va 2s. c  o  m
            }
        }
        return false;
    }
}

Related Tutorials