Sunday, January 22, 2012

Finding a service status from an activity


private boolean isMyServiceRunning(String serviceName) {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceName.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

isMyServiceRunning("com.example.MyService") will give you the status of the service.

No comments:

Post a Comment