android – 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();
}
[...]
}
根据我读到的内容,我做了一个简单的测试,我在快速游戏中连接了两个同伴.我在其中一个上禁用了WiFi连接.我以为我会看到onConnectionSuspended的祝酒词.有没有办法诱导吐司出于测试目的?
谢谢
解决方法:
当您的应用与Google Play服务包(不一定是Internet)断开连接时,会调用onConnectionSuspended.例如,当您转到设置>时,将调用回调.应用> Google Play服务>强制停止.另一个例子是您何时卸载Google Play服务.几秒后你会得到onConnectionSuspended后跟onConnectionFailed(因为重新连接尝试会失败).
也不要从onConnectionSuspended(…)调用mGoogleApiClient.connect().重新连接自动处理.
标签:android,google-play-games 来源: https://codeday.me/bug/20190929/1829907.html