You're thinking about this the wrong way. In the Android framework, things don't just die, "stopping a service" does not mean sending it a SIGKILL.
Instead, I would suspect that you should create an onStop in your service, and stop your processing there. However if you're doing some long running tasks this should probably be happening in a task or some background thread within your service anyway... Right, and how are you killing your service, you should be doing a "stopService" if you are using the service in this manner (versus binding..) Then in onStop you should have some way to "stop whatever is happening..." You might also want to reread the Service lifecycle documentation, to make sure you're understanding how things are being executed: if you're doing long running things in the service's onStartCommand, this is probably not good. Your onStartCommand should be the thing that starts doing stuff and coordinates what happens based on incoming intents. So, where in your service are you doing the work? Kris On Tue, Jan 3, 2012 at 1:54 AM, elham <[email protected]> wrote: > > Service does not have onStop() . onDestroy is getting called after the > work is done . I want onDestroy() to be called immediately after i > call stopService() . > > > On Jan 3, 10:13 am, Kristopher Micinski <[email protected]> > wrote: >> Does yourserviceonStop get called? >> >> Kris >> >> >> >> >> >> >> >> On Tue, Jan 3, 2012 at 12:09 AM,elham<[email protected]> wrote: >> > I have a apk with just user interface and another apk which has the >> > class extendingservice. The UI apk andServiceapk communicate >> > through intents . No binders involved. >> >> > Myservicestarts a operation which is niether in a thread nor in >> > AsynTask. When the user selects cancel the UI apk sends a intent to >> >Serviceapk and there i am calling stopService but theservice >> > continues . >> >> > Please let me know if you understand what is happening . >> >> > On Jan 2, 5:11 pm, Mukesh Srivastav <[email protected]> wrote: >> >> Hey, >> >> >> Are you talking about AsyncTask with a progress Dialog on a Cancel button >> >> ? or ? AServiceClass ? Please clarify >> >> >> Secondly,Serviceruns in the background without user interface, so not >> >> sure, which Asynchronous you are taking about. >> >> >> Warm Regards, >> >> *Mukesh Kumar*, >> >> Android Consultant/Freelancer, >> >> India,Hyderabad >> >> >> On Mon, Jan 2, 2012 at 5:37 PM,elham<[email protected]> wrote: >> >> > Dear All, >> >> >> > I would want tostoptheservicebefore the work completes . For >> >> > instance , when the user wishes to cancel, i want tostopthe >> >> >service. >> >> >> > Is it possible to do so? >> >> >> > Regards, >> >> >> > -- >> >> > You received this message because you are subscribed to the Google >> >> > Groups "Android Developers" group. >> >> > To post to this group, send email to [email protected] >> >> > To unsubscribe from this group, send email to >> >> > [email protected] >> >> > For more options, visit this group at >> >> >http://groups.google.com/group/android-developers?hl=en >> >> >> -- >> >> . >> >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Android Developers" group. >> > To post to this group, send email to [email protected] >> > To unsubscribe from this group, send email to >> > [email protected] >> > For more options, visit this group at >> >http://groups.google.com/group/android-developers?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

