I had some functionalities of my app broken once upgrading to Android 8, even not targeting the API 26 explicitly. In particular, the good old function to check if a Service is running (as documented on StackOverflow here: How to check if a service is running on Android?) is not working anymore.
Just to refresh our collective memory, it was this classic method:
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;
}
The problem now is that getRunningServices
is now deprecated and doesn't return the running services anymore. Does anyone have experience with this issue on Android 8?
Is there any official solution (or hack) available? I should also point out that the Service I want to look for is not in the same process/app as the code that is calling isMyServiceRunning()
(that functionality is still provided for backward compatibility reasons)