android - How to check previously started custom own service is running or not -
hi have 1 activity , 1 service class activity starting service in 1 point want start service @ same point want check service running if yes dont want call start service if not strat problem how know service running or not?
i used below code not working me other code me out
private boolean isservicerunning() { activitymanager manager = (activitymanager) getsystemservice(activity_service); (runningserviceinfo service : manager .getrunningservices(integer.max_value)) { if ("timerservice".equals(service.service.getclassname())) { toast.maketext(getapplicationcontext(), "running", 100).show(); return true; } } toast.maketext(getapplicationcontext(), "not running", 100).show(); return false; }
this code show me not tunning if running
you don't need check whether it's running or not. both startservice()
, stopservice()
handle corresponding states, if call startservice()
, service
running, nothing happen (it keep running). same goes stopservice()
.
Comments
Post a Comment