如果没有数据访问,我的游戏应用有时会因不断尝试连接 Google Play 服务而不最终放弃而锁定。
循环的错误代码是 SIGNIN_REQURIED。游戏确实会加载,但玩游戏的访问会被阻止,因为不断重新启动的 google play 连接尝试屏幕(带有旋转的加载图标)。
下面是被反复引用的代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_RESOLUTION://same constant as R_SIGN_IN_FAILED
retryConnecting();
break;
}
}
.....
private void retryConnecting() {
mIsInResolution = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
我相信这是来自简单的驱动器示例代码。不幸的是,不同 Google Play 服务功能的每个代码示例以不同的方式实现 basegameutils 库,包括仅用于连接的简单 Activity 示例代码。
我还怀疑示例代码中您定义的常量:
protected static final int REQUEST_CODE_RESOLUTION = 1;
这与“GameHelperUtils”类常量冲突:
public static final int R_SIGN_IN_FAILED = 1;
因此 onActivityResult 中的“case REQUEST_CODE_RESOLUTION:”实际上是“case R_SIGN_IN_FAILED:”。
最佳答案
我认为您应该在 onConnectionFailed() 方法中处理请求代码解析,如下所示。
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
mIntentInProgress = true;
startIntentSenderForResult(result.getResolution().getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
和 onActivityResult 如下。
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}
关于java - 游戏应用不断尝试连接 Google Play 服务而不放弃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30966111/