i developing an app for android wear. Below code with explanation of the problem
if(mGoogleApiClient.isConnected()){
K.i(\"Always called!\");
I got it working:
Init the Google API client:
private void initGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "ConnectionCallback onConnected");
if (servicesAvailable()) {
// new CheckWearableConnected().execute();
resolveNodes();
}
}
@Override
public void onConnectionSuspended(int i) {
Log.d(TAG, "ConnectionCallback onConnectionSuspended");
}
})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "ConnectionCallback onConnectionFailed");
//TODO do something on connection failed
}
})
.build();
}
Then in your onStart method connect the API client:
@Override
public void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
And to clean up, in your onStop method:
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop");
if (mGoogleApiClient != null)
if (mGoogleApiClient.isConnected()) mGoogleApiClient.disconnect();
}