Android - getRunningservices (ActivityManager) is deprecated

I want to know what MyService.javaworks or not?

I create this method:

private boolean isServiceAlive(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

it works fine, but is manager.getRunningServices()deprecated from API 26. So, is there another good solution (method) to get a list of services that are currently running?

+4
source share
1 answer

Despite the fact that it does not answer your question, I think you can still use this method for your own services:

For backward compatibility, it will still return the caller’s own services.

If you want to remove the obsolescence warning, use @SuppressWarnings("deprecation")

+4
source

Source: https://habr.com/ru/post/1683063/


All Articles