service does not stop in android -


i have developed android app enables location service , sends data server. want put control on app starting , stopping location service.

i implemented alarmmanager re-start service after time. when uncheck togglebutton stop service, not work. service not stop. it's running , sending data server continuously after stopping service.

i added ondestroy() method of service , on/off checking codes below.

@override     public void ondestroy() {         // handler.removecallbacks(sendupdatestoui);         super.ondestroy();         log.v("stop_service", "done");         toast.maketext(getapplicationcontext(), "service stopped", toast.length_short).show();         if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) {             // todo: consider calling             //    activitycompat#requestpermissions             // here request missing permissions, , overriding             //   public void onrequestpermissionsresult(int requestcode, string[] permissions,             //                                          int[] grantresults)             // handle case user grants permission. see documentation             // activitycompat#requestpermissions more details.             return;         }         locationmanager.removeupdates(listener);     } 

service on/off controlling code

tracking.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {             @override             public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {                 if (ischecked == true){                      alarmrecurrer loc = new alarmrecurrer(getapplicationcontext());                     loc.setrecurringalarmschedule(getapplicationcontext());                  }                 if (ischecked == false){                      intent locationservice = new intent(getapplicationcontext(), locationservice.class);                     getapplicationcontext().stopservice(locationservice);                 }              }         } 

can tell me possible way solve issue?

i believe have stop timer or alarmmanager you're using run service within ondestroy() of service.

a service can stopped calling stopself() method, or calling context.stopservice().

see link more information.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -