Service.onStartCommand() is directly tied to startService().  You call
startService().  That sends the Intent to the service as a command.  The
service receives it in onStartCommand().  It executes the intent.  That is
one way to use a Service.

Service.bindService() is directly tied to Service.onBind().  You call
bindService().  If the system doesn't already have the requested interface,
it calls Service.onBind() to retrieve it.  The interface is returned.  This
is another, distinct, way to use a Service.  It is unrelated to starting the
Service.

In both cases, Service.onCreate() will be called as a side-effect if the
service needs to be created in order to perform the requested operation.

You can use the two together, but semantically they are totally different in
the way they interact with the Service and how this is reflected in its
lifecycle.

On Mon, Oct 25, 2010 at 4:34 PM, doug <[email protected]> wrote:

> Thanks for your answers.  But they are not convincing.
> Context.bindService() has the option of creating a "new" service if
> the service is not created in the first place.  The life-cycle events
> for a brand new service should be identical.  But the SDK doc
> disagrees and says this about BIND_AUTO_CREATE:
>
> "Flag for bindService(Intent, ServiceConnection, int): automatically
> create the service as long as the binding exists. Note that while this
> will create the service, its onStart(Intent, int) method will still
> only be called due to an explicit call to startService(Intent). Even
> without that, though, this still provides you with access to the
> service object while the service is created. "
>
> Why?  Or let me ask it another way.  What side-effect does the
> bindService() implementation try to prevent by not calling onStart()
> with BIND_AUTO_CREATE?  Or did the engineers forget to read one of
> their own (http://static.googleusercontent.com/external_content/
> untrusted_dlcp/research.google.com/en/us/pubs/archive/32713.pdf)?
>
> doug
>
> --
> 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]<android-developers%[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