Exemple #1
0
 @Override
 protected void onPause() {
   super.onPause();
   if (mGoogleApiClient != null) Wearable.DataApi.removeListener(mGoogleApiClient, this);
   if (mSensorManager != null) mSensorManager.unregisterListener(this);
   if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) mGoogleApiClient.disconnect();
   if (mHeadTracker != null) mHeadTracker.stopTracking();
 }
  /**
   * Closes the connection to Google Play services. No calls can be made using this {@link
   * #mGoogleApiClient} after calling this method. Any method calls that haven't executed yet will
   * be canceled. That is onResult(Result) won't be called, if connection to the service hasn't been
   * established yet all calls already made will be canceled.
   */
  public void disConnect() {
    try {
      if (mDataListener != null) {
        Wearable.DataApi.removeListener(mGoogleApiClient, mDataListener);
      }
      if (mMessageListener != null) {
        Wearable.MessageApi.removeListener(mGoogleApiClient, mMessageListener);
      }
      if (mNodeListener != null) {
        Wearable.NodeApi.removeListener(mGoogleApiClient, mNodeListener);
      }

      if ((mGoogleApiClient != null)
          && (mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
        mGoogleApiClient.disconnect();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 @Override
 protected void onStop() {
   super.onStop();
   Wearable.DataApi.removeListener(mGoogleApiClient, this);
   mGoogleApiClient.disconnect();
 }