From 974540cb774f44834697775998e65b745c962b6f Mon Sep 17 00:00:00 2001 From: William French Date: Tue, 24 Nov 2015 10:07:00 -0800 Subject: [PATCH] Updates Google Play Services section with instructions for calling connect(). Staged: http://wfrench.kir.corp.google.com:9000/training/location/retrieve-current.html Change-Id: Id63b2c815fe0e2462ac91e4826b6b9aa8b88e624 --- .../training/location/retrieve-current.jd | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/docs/html/training/location/retrieve-current.jd b/docs/html/training/location/retrieve-current.jd index 5bac3fa49bb2a..206345f64b870 100644 --- a/docs/html/training/location/retrieve-current.jd +++ b/docs/html/training/location/retrieve-current.jd @@ -71,8 +71,8 @@ trainingnavtop=true block.

This lesson requires only coarse location. Request this permission with the - {@code uses-permission} element in your app manifest, as shown in the - following example: + {@code uses-permission} element in your app manifest, as the following code + snippet shows:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
@@ -92,18 +92,15 @@ trainingnavtop=true
 

In your activity's {@link android.app.Activity#onCreate onCreate()} method, - create an instance of Google API Client using - {@code GoogleApiClient.Builder}. - Use the builder to add the - {@code LocationServices} - API.

- -

The sample app defines a {@code buildGoogleApiClient()} method, called from - the activity's {@link android.app.Activity#onCreate onCreate()} method, - which includes the following code.

+ create an instance of Google API Client, using the + {@code GoogleApiClient.Builder} class to add the + + {@code LocationServices} + API, as the following code snippet shows.

-protected synchronized void buildGoogleApiClient() {
+// Create an instance of GoogleAPIClient.
+if (mGoogleApiClient == null) {
     mGoogleApiClient = new GoogleApiClient.Builder(this)
         .addConnectionCallbacks(this)
         .addOnConnectionFailedListener(this)
@@ -112,6 +109,31 @@ protected synchronized void buildGoogleApiClient() {
 }
 
+

To connect, call + + {@code connect()} + from the activity's + {@code onStart()} + method. To disconnect, call + + {@code disconnect()} from the activity's + + {@code onStop()} method. The following snippet shows an example of how + to use both of these methods. +

+ +
+protected void onStart() {
+    mGoogleApiClient.connect();
+    super.onStart();
+}
+
+protected void onStop() {
+    mGoogleApiClient.disconnect();
+    super.onStop();
+}
+
+

Get the Last Known Location

Once you have connected to Google Play services and the location services @@ -130,7 +152,7 @@ protected synchronized void buildGoogleApiClient() { object. Do this in the {@code onConnected()} callback provided by Google API Client, which is called when the client is - ready. The following code sample illustrates the request and a simple + ready. The following code snippet illustrates the request and a simple handling of the response: