is Service Running - Android Android OS

Android examples for Android OS:Service

Description

is Service Running

Demo Code


//package com.java2s;
import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

public class Main {

    public static boolean isServiceRunning(Context context, String className) {
        boolean isRunning = false;
        ActivityManager manager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> serviceList = manager
                .getRunningServices(40);
        int size = serviceList.size();
        for (int i = 0; i < size; i++) {
            if (serviceList.get(i).service.getClassName().equals(className)) {
                isRunning = true;//from   w  ww  .j  av  a2s .c o  m
                break;
            }
        }
        return isRunning;
    }
}

Related Tutorials