Android determines whether the Service is running. androidservice
private boolean isServiceStart() {ActivityManager myManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager.getRunningServices(30);for (int i = 0; i < runningService.size(); i++) {if (runningService.get(i).service.getClassName().toString().equals("com.**.**.YourService")) {return true;}}return false;}
After verification, the results are good!
Android determines whether the service is running
Go to program management-view running programs
Android determines whether the service is running
Before starting a Service, you should determine whether the Service is running or not. // This method determines your own Service --> com. android. controlAddFunctions. whether PhoneService has run public static boolean isWorked () {ActivityManager myManager = (ActivityManager) context. getSystemService (Co ntext. ACTIVITY_SERVICE); ArrayList <RunningServiceInfo> runningService = (ArrayList <RunningServi ceInfo>) myManager. getRunningServices (30); for (int I = 0; I <runningService. size (); I ++) {if (runningService. get (I ). service. getClassName (). toString (). equals ("c om. android. controlAddFunctions. phoneService ") {return true ;}} return false ;}