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/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/.MainService in 5000 ms
> 08-08 22:11:49.519 I/ActivityManager(  306): Start proc
> com.example.strangeservice for service com.example.service/.MainService
> 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/.MainService in 5000ms
> 08-08 22:27:43.629 I/ActivityManager(  306): Start proc
> com.example.strangeservice for service com.example.service/.MainService:
> 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/.MainService in 5000ms
> 08-08 22:50:04.934 I/ActivityManager(  306): Start proc
> com.example.strangeservice for service com.example.service/.MainService:
> 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 [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




-- 
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]
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

Reply via email to