本文介绍了onConnectionSuspended.怎么测试?该代码什么时候运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
    }

    [...]
}

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

根据我读到的内容,我做了一个简单的测试,在快速游戏中我将两个同伴连接起来.我禁用了其中之一的WiFi连接.我以为我会为onConnectionSuspended敬酒.有没有一种方法可以诱使吐司来进行测试?

Based on what I read I did a simple test where I connected two peers in a Quick Game. I disabled the WiFi connection on one of them. I thought that I was going to see a toast for onConnectionSuspended. Is there a way to induce that toast to come up for testing purposes?

谢谢

推荐答案

onConnectionSuspended.例如,当您转到设置>应用> Google Play服务>强制停止时,就会调用该回调.另一个示例是您何时卸载Google Play服务.几秒钟后,您将得到onConnectionSuspended,然后是onConnectionFailed(因为重新连接尝试将失败).

onConnectionSuspended gets called when your app gets disconnected from the Google Play services package (not necessarily the Internet). The callback gets invoked for instance when you go to Settings > Apps > Google Play services > Force Stop. Another example is when you would uninstall Google Play services. You would get onConnectionSuspended followed by onConnectionFailed after a couple of seconds (because a reconnection attempt would fail).

也不要从onConnectionSuspended(...)调用mGoogleApiClient.connect().重新连接是自动处理的.

Also do not call mGoogleApiClient.connect() from onConnectionSuspended(...). Reconnection is handled automatically.

这篇关于onConnectionSuspended.怎么测试?该代码什么时候运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:22