Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - getRunningservices(ActivityManager) deprecated

Tags:

java

android

I want to know MyService.java is working 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 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?

like image 790
Makhanov Madiyar Avatar asked Aug 05 '17 07:08

Makhanov Madiyar


2 Answers

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")

like image 110
geiger Avatar answered Oct 05 '22 15:10

geiger


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.

like image 31
Radesh Avatar answered Oct 05 '22 16:10

Radesh