Create a Class in a name of Services :
public class Services {
public static boolean isMyServiceRunning(Activity mActivity, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) mActivity.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}
In Your Activity :
if (Services.isMyServiceRunning(ActivityName.this, ServiceName.class)) {
// Write your condition here if service is running
}
public class Services {
public static boolean isMyServiceRunning(Activity mActivity, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) mActivity.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}
In Your Activity :
if (Services.isMyServiceRunning(ActivityName.this, ServiceName.class)) {
// Write your condition here if service is running
}