is Running Service - Android Android OS

Android examples for Android OS:Service

Description

is Running Service

Demo Code


//package com.java2s;

import java.util.List;
import android.app.ActivityManager;

import android.app.ActivityManager.RunningServiceInfo;
import android.content.ComponentName;
import android.content.Context;

public class Main {

    public static boolean isRunningService(String classname, Context context) {

        ActivityManager activity = (ActivityManager) context
                .getSystemService(context.ACTIVITY_SERVICE);

        List<RunningServiceInfo> services = activity
                .getRunningServices(1000);
        for (RunningServiceInfo runningServiceInfo : services) {
            ComponentName service = runningServiceInfo.service;
            if (service.getClassName().equals(classname)) {
                return true;
            }//from ww w  . j  a v a 2  s.  co  m
        }
        return false;
    }
}

Related Tutorials