Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static final boolean checkServiceRunning(Context c, Class<? extends Service> cls) {
        ComponentName service = new ComponentName(c, cls);
        ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
        if (am == null)
            throw new RuntimeException("Cannot check running services: ActivityManager is not available");
        for (ActivityManager.RunningServiceInfo runningService : am.getRunningServices(Integer.MAX_VALUE)) {
            if (runningService.service.equals(service))
                return true;
        }
        return false;
    }
}