Well, the unbind() call that threw the "Service not registered" was
originally bound to from a WakefulIntentService, not an Activity.
I bound to the service in doWakefulWork() and unbind() in onDestroy()
as well as when I am done with the service.
Basically I have a cleanup() method which looks like this:
public synchronized void cleanup(Context context)
{
if (this.serviceConnection != null)
{
context.getApplicationContext().unbindService(this.serviceConnection); //
Used to be just context.unbindService()
this.serviceConnection = null;
}
}
I've never even once since this error when I used to use
getApplicationContext() and now that I switched to just the
WakefulIntentService Context, I got it twice -- once myself and once
by a guy who's testing for me.
I am now back to using the Application Context, thought I don't
understand still why I have to. After all, the Service Context should
remain the same throughout the lifecycle of the Service.
On Feb 6, 6:48 am, Mark Murphy <[email protected]> wrote:
> On Sun, Feb 5, 2012 at 5:38 PM, Zsolt Vasvari <[email protected]> wrote:
> > Well, I made my change, but one of the uses for the Context is bind to a
> > service.
>
> > This now fails sometimes on unbind() with a "Service not registered"
> > message.
>
> > I asuume I still have to use the Application Context to bind to services?
>
> "Have to" is a strong term. However, particularly for activities that you:
>
> -- want to have access to a bound service, and
> -- want to allow Android to destroy and recreate on a configuration change
>
> then binding from Application is a good idea.
>
> http://commonsware.com/blog/2010/09/29/another-use-getapplicationcont...
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> _The Busy Coder's Guide to *Advanced* Android Development_ Version 2.4
> Available!
--
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