Step 1)
make a function isMyServiceRunning
call the function with name of service class
make a function isMyServiceRunning
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Step 2)call the function with name of service class
isMyServiceRunning(MyService.class)
No comments:
Post a Comment