urrentPlayerLeaderboardScore并不总是

urrentPlayerLeaderboardScore并不总是

本文介绍了Android loadCurrentPlayerLeaderboardScore并不总是返回结果值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

loadCurrentPlayerLeaderboardScore 方法有时会返回我的排行榜中的值,而其他时间没有结果,所以返回999作为 LB_SCORE 和 LB_RANK 。我连接到谷歌玩游戏服务,我能够使用 startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mClient,leaderboardId),1); 查看排行榜,所以我可以确认有效分数。我怎样才能调用 loadCurrentPlayerLeaderboardScore 更可靠和一致?

  public void populateLeaderboards(){

String [] leaderboardIdArray = getResources()。getStringArray(R.array.leaderboard_id_array);
String [] leaderboardNameArray = getResources()。getStringArray(R.array.leaderboard_name_array);

leaderboardList = new ArrayList< LeaderboardItem>();
leaderboardList.clear();

for(int i = 0; i< leaderboardIdArray.length; i ++){

Log.d(leaderboardIdArray,leaderboardIdArray [i]);

getLeaderboardData(leaderboardIdArray [i],leaderboardNameArray [i]);
LeaderboardItem(leaderboardIdArray [i],LB_NAME,String.valueOf(LB_SCORE),String.valueOf(LB_RANK));

$ b}

}

private void getLeaderboardData(final String leaderboardId,final String leaderboardName){

Game.Leaderboards.loadCurrentPlayerLeaderboardScore(mClient,leaderboardId,LeaderboardVariant.TIME_SPAN_ALL_TIME,LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback< Leaderboards.LoadPlayerScoreResult>(){
//Games.Leaderboards.loadPlayerCenteredScores(mClient,leaderboardId,LeaderboardVariant。 TIME_SPAN_ALL_TIME,LeaderboardVariant.COLLECTION_PUBLIC,1,true).setResultCallback(new ResultCallback< Leaderboards.LoadPlayerScoreResult>(){
$ b $ @Override
public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult){

if(isScoreResultValid(scoreResult)){
//在这里您可以得到像这样的分数

LB_SCORE = scoreResult.getScore()。getRawScore();
LB_RANK = scoreRe 。sult.getScore()getRank();


} else {

LB_SCORE = 999;
LB_RANK = 999;



LeaderboardItem leaderboardItem = new LeaderboardItem(leaderboardId,leaderboardName,String.valueOf(LB_SCORE),String.valueOf(LB_RANK));
leaderboardList.add(leaderboardItem);


}


});
}


private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult){
return scoreResult!= null&& GamesStatusCodes.STATUS_OK == scoreResult.getStatus()。getStatusCode()&& scoreResult.getScore()!= null;
}


解决方案

我面临类似的问题,我发现我怀疑制作通话过多会导致网络错误。所以我的建议是,你滥用游戏服务太多。


loadCurrentPlayerLeaderboardScore method sometimes returns the value from my leaderboards and other times there is no result, so 999 is returned for LB_SCORE and LB_RANK. I am connected to google play games service, I am able to view the leaderboards using the startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mClient, leaderboardId), 1); so I can confirm there are valid scores. How can I make calling loadCurrentPlayerLeaderboardScore more reliable and consistent?

public void populateLeaderboards(){

    String[] leaderboardIdArray = getResources().getStringArray(R.array.leaderboard_id_array);
    String[] leaderboardNameArray = getResources().getStringArray(R.array.leaderboard_name_array);

    leaderboardList = new ArrayList<LeaderboardItem>();
    leaderboardList.clear();

    for (int i = 0; i < leaderboardIdArray.length; i++) {

        Log.d("leaderboardIdArray", leaderboardIdArray[i]);

         getLeaderboardData(leaderboardIdArray[i],leaderboardNameArray[i]);
LeaderboardItem(leaderboardIdArray[i], LB_NAME, String.valueOf(LB_SCORE), String.valueOf(LB_RANK));


    }

}

private void getLeaderboardData(final String leaderboardId,final String  leaderboardName) {

    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mClient, leaderboardId, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
    //Games.Leaderboards.loadPlayerCenteredScores(mClient, leaderboardId, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 1, true).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {

        @Override
        public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {

            if (isScoreResultValid(scoreResult)) {
                // here you can get the score like this

                LB_SCORE = scoreResult.getScore().getRawScore();
                LB_RANK = scoreResult.getScore().getRank();


            } else {

                LB_SCORE = 999;
                LB_RANK = 999;

            }

            LeaderboardItem leaderboardItem = new LeaderboardItem(leaderboardId, leaderboardName, String.valueOf(LB_SCORE), String.valueOf(LB_RANK));
            leaderboardList.add(leaderboardItem);


        }


    });
}


private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult) {
    return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null;
}
解决方案

I faced similar issues, and I see that other post confirms my suspicions that making too many calls will result in network error. So my suggestions is that you are abusing play service too much.

这篇关于Android loadCurrentPlayerLeaderboardScore并不总是返回结果值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:21