[android-developers] IllegalArgument Exception: Service is not registered
Yes, I know this problem was discussed before, but I just don't find a
solution...
In my activity, I start and bind the service in onResume and unbind it
in onPause. There is only one ServiceConnection. I set the binder to
null in onServiceDisconnected and query that in onPause, so even if
the connection is disconnected anywhere else (which shouldn't happen
in theory) this should be handled. But still I get this Exception from
some users. How is that possible and what to do against it? Of course
I could just catch and ingore the exception, but I don't think that'd
be a good way...
Simplyfied code exampe:
public class MainActivity extends Activity {
protected IBinder myBinder = null;
protected ServiceConnection serviceConnection = new
ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder
service) {
myBinder = service;
}
public void onServiceDisconnected(ComponentName className, IBinder
service) {
myBinder = null;
}
};
public void onResume() {
startService(serviceIntent);
bindService(serviceIntent, serviceConnection,
Context.BIND_AUTO_CREATE);
}
public void onPause() {
if ( myBinder != null ) {
unbindService(serviceConnection);
}
}
}
I've also got the problem that sometimes, the onDestroy() method of
the service seems to be invoked while it's still bound to an activity,
and onServiceDisconnected() is not invoked. At least I get a
NullPointerException on a service member that has successfully been
used before, is only set to null in onDestroy(), and is checked in the
onServiceConnected() method. (If the service isn't initialized or
becomes unbound in sub activities, they're immediately finish()ed.)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home