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
Post a Comment