Monday, August 8, 2011

Re: [android-developers] Correct Binding to a service?

On Mon, Aug 8, 2011 at 11:00 AM, Boozel <boozelclark@gmail.com> wrote:
> I have a main activity that binds to a service. The service has a data
> connection where it gets data based on async tasks in my main activity.
> When is the correct time to bind and unbind from my service?

In the final onDestroy(), where by "final" I mean "not counting any
onDestroy() triggered by a configuration change, since you want to
pass the ServiceConnection and AsyncTask to the new activity
instance".

Getting binding right with an activity given configuration changes is
a PITA. If you are using fragments, you may be able to bind from the
fragment and use setRetainInstance(true) to minimize the pain, though
I haven't tried this combination yet.

> If my main activity opens another activity (a
> menu to filter the data) do i need to unbind on pause and rebind on resume?

No.

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

Android 3.1 Programming Books: http://commonsware.com/books

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