0

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? Thanks

Splitusa
  • 1,181
  • 7
  • 31
  • 51

1 Answers1

0

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?

Community
  • 1
  • 1
Suchi
  • 9,989
  • 23
  • 68
  • 112