Still occupies some amount of memory though, and the service's onCreate might not be cheap.
Anyways, I guess this is one of those little undocumented things you just have to learn. Do not rely on START_NOT_STICKY if you both start and bind to a service if you don't want the service to stay around forever as a cached process after you've unbound it. On Thursday, August 9, 2012 7:15:09 PM UTC+2, Dianne Hackborn wrote: > > Binding to a service can only make that service's process as important as > the process of the client binding to it. If the client process is in the > background, it can't bring the service up beyond the background, so it > doesn't count as a running process but a cached process. > > On Thu, Aug 9, 2012 at 3:09 AM, Johan Appelgren > <[email protected]<javascript:> > > wrote: > >> Ok, thanks. But shouldn't it (non-sticky service with no active >> connections, nothing is bound to it) show up in the Running Services view >> when it has been restarted? Or is that only for sticky services? >> >> >> On Thursday, August 9, 2012 8:35:50 AM UTC+2, Dianne Hackborn wrote: >> >>> Binding and starting are completely orthogonal things. You bind to a >>> service to establish a persistent connection to it. You start a service to >>> have it run for some undefined amount of time separately from the caller. >>> A service needs to remain created as long as it is being asked to do >>> either of these things. >>> >>> If you don't want it to stay created, either don't bind to it when you >>> don't want it around, or don't use BIND_AUTO_CREATE so you aren't forcing >>> it to remain created while bound to it. >>> >>> On Wed, Aug 8, 2012 at 10:46 PM, Johan Appelgren >>> <[email protected]>wrote: >>> >>>> So START_NOT_STICKY has no effect once I've bound to it even if I >>>> unbind? I must explicitly use stopService if the service has ever been >>>> bound to even if there are no more connection? >>>> >>>> >>>> On Thursday, August 9, 2012 2:54:41 AM UTC+2, Dianne Hackborn wrote: >>>> >>>>> If you bind to it with BIND_AUTO_CREATE, you are saying you want the >>>>> service to be created as long as you are bound to it. >>>>> >>>>> From the documentation: >>>>> >>>>> A service can be both started and have connections bound to it. In >>>>> such a case, the system will keep the service running as long as either >>>>> it >>>>> is started or there are one or more connections to it with the >>>>> Context.BIND_AUTO_CREATE flag. >>>>> >>>>> http://developer.android.com/**r**eference/android/app/Service.**h** >>>>> tml <http://developer.android.com/reference/android/app/Service.html> >>>>> >>>>> On Wed, Aug 8, 2012 at 1:52 PM, Johan Appelgren >>>>> <[email protected]>wrote: >>>>> >>>>>> If I have a simple service that returns START_NOT_STICKY in >>>>>> onStartCommand and I both start it explicitly (startService) and bind to >>>>>> it >>>>>> (bindService) in onCreate of my activity the service gets recreated >>>>>> after >>>>>> it has been killed over and over again. I unbind the service in onPause >>>>>> of >>>>>> my activity. >>>>>> >>>>>> Logcat shows that the service is scheduled for restart and is >>>>>> restarted over and over again. The service is not shown as running after >>>>>> it's been recreated in Settings -> Apps -> Running. >>>>>> >>>>>> 08-08 21:57:25.081 D/ExampleActivity(23715): onPause >>>>>> 08-08 22:11:44.480 W/ActivityManager( 306): Scheduling restart of >>>>>> crashed service com.example.service/.**MainServi**ce in 5000 ms >>>>>> 08-08 22:11:49.519 I/ActivityManager( 306): Start proc >>>>>> com.example.strangeservice for service com.example.service/.** >>>>>> MainServi**ce >>>>>> 08-08 22:11:49.597 D/ExampleService(24079): onCreate >>>>>> 08-08 22:27:38.551 I/ActivityManager( 306): No longer want >>>>>> com.example.service (pid 24079): hidden #16 >>>>>> 08-08 22:27:38.574 W/ActivityManager( 306): Scheduling restart of >>>>>> crashed service com.example.service/.**MainServi**ce in 5000ms >>>>>> 08-08 22:27:43.629 I/ActivityManager( 306): Start proc >>>>>> com.example.strangeservice for service com.example.service/.** >>>>>> MainServi**ce: pid=24401 uid=10101 gids={1028} >>>>>> 08-08 22:27:43.785 D/ExampleService(24401): onCreate >>>>>> 08-08 22:49:59.871 I/ActivityManager( 306): Process >>>>>> com.example.service (pid 24401) has died. >>>>>> 08-08 22:49:59.871 W/ActivityManager( 306): Scheduling restart of >>>>>> crashed service com.example.service/.**MainServi**ce in 5000ms >>>>>> 08-08 22:50:04.934 I/ActivityManager( 306): Start proc >>>>>> com.example.strangeservice for service com.example.service/.** >>>>>> MainServi**ce: pid=24857 uid=10101 gids={1028} >>>>>> 08-08 22:50:05.051 D/ExampleService(24857): onCreate >>>>>> >>>>>> I thought START_NOT_STICKY meant that once it gets killed by Android >>>>>> it wont be restarted unless I explicitly start it again. Or does binding >>>>>> to >>>>>> a service override that and make the service sticky? >>>>>> >>>>>> I've been testing this on a Galaxy Nexus with stock Android 4.1.1. >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Android Developers" group. >>>>>> To post to this group, send email to android-d...@**googlegroups.com >>>>>> >>>>>> To unsubscribe from this group, send email to >>>>>> android-developers+**unsubscribe**@googlegroups.com >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/**group**/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en> >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Dianne Hackborn >>>>> Android framework engineer >>>>> [email protected] >>>>> >>>>> >>>>> Note: please don't send private questions to me, as I don't have time >>>>> to provide private support, and so won't reply to such e-mails. All such >>>>> questions should be posted on public forums, where I and others can see >>>>> and >>>>> answer them. >>>>> >>>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to android-d...@**googlegroups.com >>>> To unsubscribe from this group, send email to >>>> android-developers+**[email protected] >>>> For more options, visit this group at >>>> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en> >>>> >>> >>> >>> >>> -- >>> Dianne Hackborn >>> Android framework engineer >>> [email protected] >>> >>> Note: please don't send private questions to me, as I don't have time to >>> provide private support, and so won't reply to such e-mails. All such >>> questions should be posted on public forums, where I and others can see and >>> answer them. >>> >>> -- >> 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]<javascript:> >> To unsubscribe from this group, send email to >> [email protected] <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > > > -- > Dianne Hackborn > Android framework engineer > [email protected] <javascript:> > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. > > -- 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

