I want to know MyService.java
is working or not?
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 manager.getRunningServices()
is deprecated from API 26. So have we another good solution(method) to get a list of the services that are currently running?
Despite it doesn't answer your question, I think you still can use this method for your own services:
For backwards compatibility, it will still return the caller's own services.
If you'd just like to remove the deprecation warning, use @SuppressWarnings("deprecation")
Welcome to Android O
Another Annoying bug of android Oreo, there is just Deprecated annotation and there is no other way to do this. but maybe in the past android developers decide to create alternative function.
For now as Document says continue to use getRunningServices
and use @SuppressWarnings("deprecation")
above of your function to get rid of warning.
As of Build.VERSION_CODES.O, this method is no longer available to third party applications. For backwards compatibility, it will still return the caller's own services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With