Checks to see if a Form Service is running. - Android Android OS

Android examples for Android OS:Service

Description

Checks to see if a Form Service is running.

Demo Code


//package com.java2s;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;

import android.content.Context;

public class Main {
    /**//from www .  j  a v a 2s .  c  o m
     * Checks to see if a Form Service is running. This will only check the current app's FormServices.
     * 
     * @param context
     * @param className The name of the service you want to check.
     * @return
     */
    public static boolean isFormServiceRunning(Context context,
            String className) {
        ActivityManager manager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        String serviceFullName = context.getPackageName() + className;
        for (RunningServiceInfo service : manager
                .getRunningServices(Integer.MAX_VALUE)) {
            if (serviceFullName.equalsIgnoreCase(service.service
                    .getClassName())) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials