android - Creating start stop service button -


i want create single button serves both functions of starting , stopping service.

also want make sure if user quits application , again comes according whether service running or not, want show appropriate text on button.

so in short, thing can know if service running or not ?

you can check if service running or not below code. rest of question logic based once find service running or not.

private boolean ismyservicerunning() {     activitymanager manager = (activitymanager) getsystemservice(activity_service);     (runningserviceinfo service : manager.getrunningservices(integer.max_value)) {         if ("com.example.myservice".equals(service.service.getclassname())) {             return true;         }     }     return false; } 

i refer this answer check it


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -