onConnectionSuspended.怎么测试?这段代码何时运行?

Eae*_*Eae 9 android google-play-games

public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks {

    @Override
    public void onConnectionSuspended(int i) {
        Log.d(TAG, "onConnectionSuspended() called. Trying to reconnect.");
        sendToast("onConnectionSuspended() called. Trying to reconnect.");
        mGoogleApiClient.connect();
    }

    [...]
}
Run Code Online (Sandbox Code Playgroud)

我已阅读文档:https: //developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.ConnectionCallbacks.html

根据我读到的内容,我做了一个简单的测试,我在快速游戏中连接了两个同伴.我在其中一个上禁用了WiFi连接.我以为我会看到onConnectionSuspended的祝酒词.有没有办法诱导吐司出于测试目的?

谢谢

Eug*_*nec 18

onConnectionSuspended当您的应用与Google Play服务包(不一定是互联网)断开连接时会被调用.例如,当您转到设置>应用> Google Play服务>强制停止时,将调用回调.另一个例子是您何时卸载Google Play服务.几秒钟之后你会得到onConnectionSuspended跟随onConnectionFailed(因为重新连接尝试会失败).

也不要打电话mGoogleApiClient.connect()onConnectionSuspended(...).重新连接自动处理.

  • 我注意到,根据我的经验,它会自动处理. (3认同)
  • 根据该代码的作者,在http://stackoverflow.com/a/26147518/252080,重新连接是自动的. (3认同)