如何从谷歌游戏服务处理断开? [英] How to handle disconnect from Google Game Services?
问题描述
我使用谷歌游戏服务排行榜。显示它是这样的:
I use Google Game Services for leaderboards. Showing it like this:
static public void showLeaderboard(String lid)
{
if (isLogined() == 1)
{
Log.i(TAG, "Showing leaderboard...");
Intent intent = Games.Leaderboards.getLeaderboardIntent(mClient, lid);
mApp.startActivityForResult(intent, 1);
}
}
static public int isLogined()
{
if (mClient != null && mClient.isConnected())
return 1;
return 0;
}
但是当我打开排行榜和注销从与谷歌谷歌的用户界面游戏服务(动作溢出菜单图标 - >设置 - >退出),我一直有我的isLogined()== 1。所以,当我打电话showLeaderboard()第二时间 - 游戏与下降情况除外:
But when I open leaderboards and logout from Google Game Services with Google UI (Action Overflow menu icon -> Settings -> Sign out) I keep having my isLogined() == 1. So, when I call showLeaderboard() second time - game falls with exception:
java.lang.SecurityException: Not signed in when calling API
GoogleApiClient具有用于连接,但不为断开回调。
我该如何处理来自GGS唱出了与谷歌的用户界面?
GoogleApiClient has callbacks for connection but not for disconnection. How can I handle sing out from GGS with google UI?
推荐答案
为了把一切都同步增长必须实现的onActivityResult
正常。
In order to keep everything synced up you MUST implement onActivityResult
properly.
这看起来应该如下:
@Override
protected void onActivityResult(int request, int response, Intent data) {
// check for "inconsistent state"
if ( responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && requestCode == <your_request_code_here> ) {
// force a disconnect to sync up state, ensuring that mClient reports "not connected"
mClient.disconnect();
}
}
请注意:只要确保替换&LT; your_request_ code_here&GT;
在code。与你使用的请求code(这仅仅是 1在你的榜样
)。您可能需要检查多个请求codeS如果你使用的成就也是如此。
NOTE: just make sure to replace <your_request_code_here>
in the code with the request code you used (which is just 1
in your example). You may need to check for multiple request codes if you use achievements as well.
这篇关于如何从谷歌游戏服务处理断开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!