我遇到了Google Play游戏服务的问题,其中排行榜随机启动,并在切换应用和选择主页时恢复游戏。我该如何改变这种行为?
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();
}
答案 0 :(得分:2)
我认为这是因为在你的方法'onSignInSucceeded'中你调用'onShowLeaderboard();'因此,每次启动应用程序(第一次或恢复)时,它都会登录,如果登录过程成功,那么它将启动方法'onShowLeaderboard();'
答案 1 :(得分:0)
对于特定的排行榜,您应该使用:
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(),
YOUR_LEADERBOARD_ID), REQUEST_LEADERBOARD);
而不是使用:
startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
RC_UNUSED);