1

I was shocked that this is deprecated and it will return the caller's own services on Oreo(API 26).
Is there alternative way to get list of services on Oreo?

  • 1
    no, no alternatives, they warned you that it was for debugging purposes only, what do you need it for? – pskink Aug 22 '17 at 12:45
  • @pskink I need it to count workers in other apps. – LesMiserables25 Aug 22 '17 at 14:06
  • to count workers? what workers? – pskink Aug 22 '17 at 14:09
  • The simple answer is no, but if you extended your question as to what you used it for, we can probably come up with a solution to help. I took a shot in the dark, assuming you used the function to keep track of your application's services, and posted an answer. –  May 17 '18 at 06:04
  • Possible duplicate of https://stackoverflow.com/questions/45715905/android-o-replacement-for-getrunningservices – JoeyG Apr 01 '19 at 13:54

1 Answers1

4

it is true the "getRunningServices()" has been deprecated, and No there are no alternatives. This function was originally created for internal application testing. Since this function's creation, Google found that this could be exploited by programmers with dark intentions. Basically, it is not a good idea for others to know what services you are currently running. For example, if you are running a service for anti-malware, a program can be created to notice this, then start a new service to block it, or some other similar usage.

If you were using this function to keep track of your application's running services, you can do what I did to remove all usage of the function. I simply just made a singleton class that has a boolean variable for when I started or stopped for each service. When a service starts, set the boolean in the singleton to true, and when it stops, set the singleton's boolean value to false. In other classes, you can simply call the singleton, plus the variable name to test if the service is running.

For example:

// Singleton class
public class SingletonServiceManager {

    public static boolean isMyServiceRunning = false;

}

// Some other class
if(SingletonServiceManager.isMyServiceRunning == true){
    // do something (btw, you don't need the == true portion)
}

You didn't explain why you needed to use this function, so I hope this helps in some way. Good luck!

  • The question is specifically asking for finding running services from other applications; this will only keep track of the services in a single app. Not sure how this got marked as an answer but it is incorrect. – JoeyG Apr 01 '19 at 13:52
  • the service can run in foreground/background, getservices returns services that have a property foreground (Set to true if the service has asked to run as a foreground process) – IulianT Oct 24 '19 at 11:03