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

烂漫一生 提交于 2019-11-30 01:13:38

问题


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 ?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/26056148/googleapiclient-onconnectionsuspended-should-i-call-mgoogleapiclient-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!