/*** How to determine if a service is running * *@paramMcontext *@paramServiceName * is the package name + service class name (for example: net.loonggg.testbackstage.TestService) *@returntrue to indicate that the service is not running, false*/ Public Booleanisservicework (Context mcontext, String serviceName) {BooleanIswork =false; Activitymanager Myam=(Activitymanager) mcontext. Getsystemservice (Context.activity_service); List<RunningServiceInfo> myList = myam.getrunningservices (40); if(Mylist.size () <= 0) { return false; } for(inti = 0; I < mylist.size (); i++) {String mname=Mylist.get (i). Service.getclassname (). toString (); if(Mname.equals (serviceName)) {iswork=true; Break; } } returniswork; }
Code reprint main record: Gets the name of the service that is currently running.
How Android determines whether a service is running