From ea58be972d43dbc21cc5381fd72e1f5df8727337 Mon Sep 17 00:00:00 2001
From: Daniel Yu
Date: Fri, 20 Nov 2015 14:08:34 -0800
Subject: [PATCH] docs: Fixing details on when clients unbind from Bound
Service
Docs were slightly contradictory on when clients should unbind.
Changed a few sections to point to one "source of truth" section
that explains the appropriate times to call unbindService().
Updated with corrections to issues found by Andrew and Dave.
Bug: 8135078
Change-Id: If8afb998cbd2efceef075ee6633cf0744c50d1df
---
docs/html/guide/components/bound-services.jd | 24 +++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/docs/html/guide/components/bound-services.jd b/docs/html/guide/components/bound-services.jd
index c2ac6074aaec3..f71ba8736be25 100644
--- a/docs/html/guide/components/bound-services.jd
+++ b/docs/html/guide/components/bound-services.jd
@@ -15,7 +15,11 @@ parent.link=services.html
Using a Messenger
- Binding to a Service
+ Binding to a Service
+
+ - Additional notes
+
+
Managing the Lifecycle of a Bound Service
@@ -309,8 +313,11 @@ public class BindingActivity extends Activity {
android.content.ServiceConnection#onServiceConnected onServiceConnected()} callback. The next
section provides more information about this process of binding to the service.
-Note: The example above doesn't explicitly unbind from the service,
-but all clients should unbind at an appropriate time (such as when the activity pauses).
+Note: In the example above, the
+{@link android.app.Activity#onStop onStop()} method unbinds the client from the service. Clients
+should unbind from services at appropriate times, as discussed in
+Additional Notes.
+
For more sample code, see the {@code
@@ -538,10 +545,11 @@ onServiceConnected()} callback method, you can begin making calls to the service
the methods defined by the interface.
To disconnect from the service, call {@link
android.content.Context#unbindService unbindService()}.
- When your client is destroyed, it will unbind from the service, but you should always unbind
-when you're done interacting with the service or when your activity pauses so that the service can
-shutdown while its not being used. (Appropriate times to bind and unbind is discussed
-more below.)
+ If your client is still bound to a service when your app destroys the client, destruction
+causes the client to unbind. It is better practice to unbind the client as soon as it is done
+interacting with the service. Doing so allows the idle service to shut down. For more information
+about appropriate times to bind and unbind, see Additional Notes.
+
@@ -591,7 +599,7 @@ and {@link android.content.Context#BIND_NOT_FOREGROUND}, or {@code 0} for none.<
-Additional notes
+Additional notes
Here are some important notes about binding to a service: