Got it. That's very helpful.

I have a remaining uncertainty.  Can multiple Activities use the same
ServiceConnection with bindService() and unbindService()?

My idea is to have Activities call bindService in Activity.onStart()
and unbindService in Activity.onStop() and just leverage using the
same ServiceConnection.  So when one Activity calls onStop the next
started Activity will have already called onStart() and the Service
will be continuously bound to the current active foreground Activity.
As soon an Activity comes to the front that does not call
bindService() the Service becomes eligible for reaping...  Does that
make sense?

On Nov 1, 2:19 pm, Dianne Hackborn <[email protected]> wrote:
> On Mon, Nov 1, 2010 at 12:30 PM, jotobjects <[email protected]> wrote:
> > Can a Service find out what component caused onBind() and unBind() to
> > be invoked?
>
> No.  onBind() is only called once for the first request; after that the
> system keeps the IBinder and hands it to other requests without bothering
> the service.
>
> > Possibly related second question - Why are the Intent extras NOT
> > available in onBind() and unBind() as stated in the documentation for
> > those methods?
>
> Because it is only called for the first request for that particular Intent
> (as defined by the intent filtering).  The extras are not part of intent
> matching, so relying on them here would be broken.
>
> Keep your onBind() interaction simple.  After that there is a full interface
> between the service and its client, with which they can exchange whatever
> information they want.  You should look at the Intent as simply specifying
> the interface the client would like to bind to.
>
> --
> 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