How would I go about creating a flag so that if a service
is running, and the user clicks on another listview
item that it will check to see if a service
is running, and thus stop it? Tha开发者_如何学Pythonnks
You could use something like -
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.example.MyService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Ref - How to check if a service is running on Android?
精彩评论