Created
January 15, 2016 02:49
-
-
Save waveacme/b04a3f3de4eb22767e9f to your computer and use it in GitHub Desktop.
how to check service running stat in android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
//... | |
public void CheckService(View v) { | |
boolean isRunning = isMyServiceRunning(myService.class); | |
Log.d(TAG, "my service running status: " + isRunning); | |
} | |
private boolean isMyServiceRunning(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; | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reference stackoverflow