I am using GoogleApiClient in a service to request fused location updates. Every thing is working correctly, but sometimes the connection is suspended and onConnectionSuspended is called.
@Override
public void onCreate() {
...
mGoogleApiClient = new GoogleApiClient.Builder(this) // this is a Context
.addApi(LocationServices.API)
.addConnectionCallbacks(this) // this is a [GoogleApiClient.ConnectionCallbacks][1]
.addOnConnectionFailedListener(this) //
.build();
mGoogleApiClient.connect();
...
}
@Override
public void onConnectionSuspended(int arg0) {
// what should i do here ? should i call mGoogleApiClient.connect() again ? ?
}
In the link above (ConnectionCallback doc) it says :
Applications should disable UI components that require the service, and wait for a call to onConnected(Bundle) to re-enable them.
But how this call to onConnected will happen ? should i call mGoogleApiClient.connect() again ? or the mGoogleApiClient will continue trying to connect even after a connection suspension ?
GoogleApiClient will automatically try to reconnect. You do not need to call connect()
again.
The onConnected()
doc says the follwing:
After calling connect(), this method will be invoked asynchronously when the connect request has successfully completed.
This implies that you have to call connect()
otherwise onConnected()
won't be called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With