Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleApiClient onConnectionSuspended , should i call mGoogleApiClient.connect() again?

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 ?

like image 815
Tourki Avatar asked Sep 26 '14 09:09

Tourki


2 Answers

GoogleApiClient will automatically try to reconnect. You do not need to call connect() again.

like image 102
Hounshell Avatar answered Sep 23 '22 16:09

Hounshell


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.

like image 21
Ogen Avatar answered Sep 23 '22 16:09

Ogen