Thursday, September 23, 2010

[android-developers] onRetainNonConfigurationInstance() and ServiceConnection

In an earlier thread on this group, it was pointed out that it is safe
to pass a properly-constructed AsyncTask object from an old activity
to a new one via onRetainNonConfigurationInstance(), so we can keep
the background work running when the device changes orientation, dock
status, etc.

What about ServiceConnection?

In other words, if an activity is bound to a service, is there a way
we can keep the binding alive during the configuration change, by
passing a properly-constructed ServiceConnection from the old activity
to the new? Or do we have to unbind in the old activity and bind again
in the new one?

Since ServiceConnection is just an interface, it should be fairly
trivial to have that object be clean for passing via
onRetainNonConfigurationInstance(). I'm just not sure if there's
something else held inside Android's innards that might get confused
if we do this.

Thoughts?

Thanks!

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

--
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

No comments:

Post a Comment