本文介绍了GoogleApiClient onConnectionSuspended,我应该()再次呼吁mGoogleApiClient.connect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GoogleApiClient在服务请求融合位置更新。每一件事情工作正常,但有时连接已暂停,onConnectionSuspended被调用。

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 ? ? 

}

在上面(ConnectionCallback DOC)的链接,它说:

In the link above (ConnectionCallback doc) it says :

应用程序应该禁用那些需要服务的UI组件,并等待调用onConnected(捆绑)重新启用它们。

不过,如何调用onConnected会怎样呢?我应该()再次呼吁mGoogleApiClient.connect?或mGoogleApiClient将继续努力,即使连接后中止连接?

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会自动尝试重新连接。你并不需要调用连接()了。

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

这篇关于GoogleApiClient onConnectionSuspended,我应该()再次呼吁mGoogleApiClient.connect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 17:05