@Override public void onConnectionSuspended(final int cause) { Wearable.DataApi.removeListener(mGoogleApiClient, this); finish(); }
@Override protected void onPause() { super.onPause(); Wearable.DataApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); }
@Override protected void onStop() { super.onStop(); Wearable.MessageApi.removeListener(mGoogleApiClient, this); Wearable.DataApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); }
@Override protected void onStop() { super.onStop(); Wearable.MessageApi.removeListener(mGoogleApiClient, this); Wearable.DataApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); }
@Override public void onDestroy() { if (!mResolvingError) { Wearable.MessageApi.removeListener(mGoogleApiClient, this); Wearable.DataApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); stopAlarm(); } mTextToSpeech.shutdown(); mAlarmPlayer.release(); mDatabase.close(); super.onDestroy(); }
@Override public void onDestroy() { if (mApiClient != null) { Wearable.MessageApi.removeListener(mApiClient, ConnectedWatchFace.this); Wearable.NodeApi.removeListener(mApiClient, ConnectedWatchFace.this); Wearable.DataApi.removeListener(mApiClient, ConnectedWatchFace.this); } if(mWearableAPIHelper != null) { mWearableAPIHelper.onDestroy(); } super.onDestroy(); }
@Override public void onVisibilityChanged(boolean visible) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onVisibilityChanged: " + visible); } super.onVisibilityChanged(visible); if (visible) { mGoogleApiClient.connect(); registerReceiver(); // Update time zone and date formats, in case they changed while we weren't visible. mCalendar.setTimeZone(TimeZone.getDefault()); initFormats(); } else { unregisterReceiver(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { Wearable.DataApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); } } // Whether the timer should be running depends on whether we're visible (as well as // whether we're in ambient mode), so we may need to start or stop the timer. updateTimer(); }
@Override public void onConnectionFailed(ConnectionResult result) { if (mResolvingError) { // Already attempting to resolve an error. return; } else if (result.hasResolution() && mActivity != null) { try { mResolvingError = true; result.startResolutionForResult(mActivity, 1000); } catch (IntentSender.SendIntentException e) { // There was an error with the resolution intent. Try again. mGoogleApiClient.connect(); } } else { Log.e(TAG, "Connection to Google API client has failed"); mResolvingError = false; if (mListener != null) mListener.onDataUpdated(); Wearable.MessageApi.removeListener(mGoogleApiClient, this); Wearable.DataApi.removeListener(mGoogleApiClient, this); } }
@Override protected void onStop() { Wearable.DataApi.removeListener(mGoogleApiClient, this); Wearable.MessageApi.removeListener(mGoogleApiClient, this); // Tell the wearable to end the quiz (counting unanswered questions as skipped), and then // disconnect mGoogleApiClient. DataMap dataMap = new DataMap(); dataMap.putInt(NUM_CORRECT, mNumCorrect); dataMap.putInt(NUM_INCORRECT, mNumIncorrect); if (mHasQuestionBeenAsked) { mNumSkipped += 1; } mNumSkipped += mFutureQuestions.size(); dataMap.putInt(NUM_SKIPPED, mNumSkipped); if (mNumCorrect + mNumIncorrect + mNumSkipped > 0) { sendMessageToWearable(QUIZ_EXITED_PATH, dataMap.toByteArray()); } clearQuizStatus(); super.onStop(); }
@Override public void onVisibilityChanged(boolean visible) { super.onVisibilityChanged(visible); if (visible) { hide = false; mGoogleApiClient.connect(); registerReceiver(); // Update time zone in case it changed while we weren't visible. mTime.clear(TimeZone.getDefault().getID()); mTime.setToNow(); } else { hide= true; unregisterReceiver(); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { Wearable.DataApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); } invalidate(); } // Whether the timer should be running depends on whether we're visible (as well as // whether we're in ambient mode), so we may need to start or stop the timer. updateTimer(); }