I'm binding to a local Service
(that is, not using IPC and AIDL) from several activities. I want to ensure that I'm not holding references to this service from activities that the user isn't using.
My options are: 1.) to bind to the service in onCreate()
and unbind in onDestroy()
.
2.) bind in onStart()
and unbind in onStop()
.
3.) bind in onResume()
and unbind in `onPause()
. Or some combination of these.
Which is the best-practice way of binding and unbinding to a local service? Do I not need to be concerned with holding local connections from stopped activities?
Additionally, once bound to this particular service I am retrieving a Cursor
which is attached to my ListActivity
via a CursorAdapter
. The data retrieved by the Cursor may have changed while the Activity was out of view so I want to requery it when the Activity is shown again. If I bind in onCreate()
I can requery in onRestart()
. If I bind in onResume()
each time the data will be fresh because I'll query it in the Service's connected callback.
Thoughts, comments, critiques or suggestions?