Thanks.  That's exactly what I want to do!

On Nov 1, 4:01 pm, Dianne Hackborn <[email protected]> wrote:
> On Mon, Nov 1, 2010 at 3:50 PM, jotobjects <[email protected]> wrote:
> > I have a remaining uncertainty.  Can multiple Activities use the same
> > ServiceConnection with bindService() and unbindService()?
>
> I would recommend against that.  In theory it would work, but I think you
> are going to be in a world of trouble once you start trying to figure out
> what is going on inside your service connection.
>
> > 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?
>
> That won't do what you want -- you will still see individual
> connected/disconnected calls for each binding.
>
> This is a good place for use of a singleton -- write a singleton that
> manages the connections, with activities telling when they start and stop.
>  It can ensure it is bound as long as at least one activity is started.  Be
> sure to use Context.getApplicationContext() to bind with that instead of
> with whatever activity happened to called.
>
> --
> 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