Android 谷歌游戏服务
我对Google Play游戏服务有一个问题,在启动和恢复游戏时,从切换应用程序到选择主页,排行榜会随机启动。我怎样才能改变这种行为Android 谷歌游戏服务,android,Android,我对Google Play游戏服务有一个问题,在启动和恢复游戏时,从切换应用程序到选择主页,排行榜会随机启动。我怎样才能改变这种行为 if (isSignedIn()) { startActivityForResult(getGamesClient().getAllLeaderboardsIntent(), RC_UNUSED); public int gameMode; public static void showLeaderboard(in
if (isSignedIn()) {
startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
RC_UNUSED);
public int gameMode;
public static void showLeaderboard(int mode) {
me.gameMode = mode;
me.runOnUiThread(new Runnable() {
public void run() {
if (me.isSignedIn())
me.onShowLeaderboard();
else
me.SignIn();
}
});
}
public static void submitScore(final int score) {
me.gameMode = score / 1000000;
me.runOnUiThread(new Runnable() {
public void run() {
me.onSubmitScore(score % 1000000);
}
});
}
public void onShowLeaderboard() {
if (isSignedIn()) {
startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
RC_UNUSED);
} else {
showAlert(getString(R.string.signing_in));
this.SignIn();
}
}
public void onSubmitScore(int score) {
if (isSignedIn()) {
switch (gameMode) {
case 1:
getGamesClient().submitScore(getString(R.string.leaderboard1),
score);
break;
case 2:
getGamesClient().submitScore(getString(R.string.leaderboard2),
score);
break;
case 3:
getGamesClient().submitScore(getString(R.string.leaderboard3),
score);
break;
}
} else {
showAlert(getString(R.string.signing_in));
this.SignIn();
}
}
boolean verifyPlaceholderIdsReplaced() {
final boolean CHECK_PKGNAME = true; // set to false to disable check
// (not recommended!)
// Did the developer forget to change the package name?
if (CHECK_PKGNAME && getPackageName().startsWith("com.google.example.")) {
Log.e(TAG,
"*** Sample setup problem: "
+ "package name cannot be com.google.example.*. Use your own "
+ "package name.");
return false;
}
return true;
}
public void SignIn() {
if (!verifyPlaceholderIdsReplaced()) {
showAlert("Sample not set up correctly. See README.");
return;
}
// start the sign-in flow
beginUserInitiatedSignIn();
}
@Override
public void onSignInFailed() {
System.out.println("SignIn Failed!");
}
@Override
public void onSignInSucceeded() {
System.out.println("SignIn Successed!");
onShowLeaderboard();
}
我认为这是因为在您的方法“OnSignensAccepted”中,您调用了“OnSowleadboard();”因此,每次启动(第一次或恢复)应用程序时,它都将登录,如果登录过程成功,则它将启动方法“onshowleadboard();” 对于特定的引导板,您应该使用:
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(),
YOUR_LEADERBOARD_ID), REQUEST_LEADERBOARD);
而不是使用:
startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
RC_UNUSED);
有人能帮忙吗?