turnbasedmultiplayer - OnturnBasedMatchEned未被调用[英] TurnBasedMultiplayer - onTurnBasedMatchesLoaded does not get called

本文是小编为大家收集整理的关于turnbasedmultiplayer - OnturnBasedMatchEned未被调用的处理方法,想解了turnbasedmultiplayer - OnturnBasedMatchEned未被调用的问题怎么解决?turnbasedmultiplayer - OnturnBasedMatchEned未被调用问题的解决办法?turnbasedmultiplayer - OnturnBasedMatchEned未被调用问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

我正在使用我的Android应用程序中的Google Play游戏服务,我正在尝试使用状态加载所有转向的匹配状态:turnbasedmatch.match_turn_status_my_turn

public class TurnBasedMulti  implements 
    OnInvitationReceivedListener, OnTurnBasedMatchUpdateReceivedListener, OnTurnBasedMatchesLoadedListener{

    private GoogleApiClient googleApiClient;

    public TurnBasedMulti(){
        googleApiClient = new GoogleApiClient.Builder(this)
           .addApi(Games.API)
           .build();

        googleApiClient.connect();
    }

    public void loadMatches(){
        Log.i("TBM", "load matches async");
        Games.TurnBasedMultiplayer.loadMatchesByStatus(googleApiClient, TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN);
    }

    @Override
    public void onConnected(Bundle arg0) {
        Log.i("googleApiClient", "connected");
        Games.TurnBasedMultiplayer.registerMatchUpdateListener(googleApiClient, this);
    }

    @Override
    public void onTurnBasedMatchesLoaded(int statusCode, LoadMatchesResponse response) {
        Log.i("TBM", "matches loaded");
        TurnBasedMatchBuffer matchBuffer = response.getMyTurnMatches();
        matchBuffer.close();

        response.getCompletedMatches().close();
        response.getTheirTurnMatches().close();
        response.getInvitations().close();
        response.close();
    }

}

logcat输出:

03-15 21:16:04.594: I/googleApiClient(6066): connected
03-15 21:16:04.666: I/TBM(6066): load matches async
03-15 21:16:18.366: E/DataBuffer(6066): Internal data leak within a DataBuffer object detected!  Be sure to explicitly call close() on all DataBuffer extending objects when you are done with them. (com.google.android.gms.games.multiplayer.turnbased.TurnBasedMatchBuffer@a69f2d40)

OnTurnBasedMatchEned未被调用.我做错了什么?

推荐答案

您必须注册ResultCallback

 Games.TurnBasedMultiplayer.loadMatchesByStatus(googleApiClient, TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN).setResultCallback(
        new ResultCallback<TurnBasedMultiplayer.LoadMatchesResult>()
        {
          @Override
          public void onResult(LoadMatchesResult result)
          {

          }
        });

本文地址:https://www.itbaoku.cn/post/157731.html

问题描述

I am using the google play games service in my android app and I am trying to load all turn based matches with the status: TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN

public class TurnBasedMulti  implements 
    OnInvitationReceivedListener, OnTurnBasedMatchUpdateReceivedListener, OnTurnBasedMatchesLoadedListener{

    private GoogleApiClient googleApiClient;

    public TurnBasedMulti(){
        googleApiClient = new GoogleApiClient.Builder(this)
           .addApi(Games.API)
           .build();

        googleApiClient.connect();
    }

    public void loadMatches(){
        Log.i("TBM", "load matches async");
        Games.TurnBasedMultiplayer.loadMatchesByStatus(googleApiClient, TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN);
    }

    @Override
    public void onConnected(Bundle arg0) {
        Log.i("googleApiClient", "connected");
        Games.TurnBasedMultiplayer.registerMatchUpdateListener(googleApiClient, this);
    }

    @Override
    public void onTurnBasedMatchesLoaded(int statusCode, LoadMatchesResponse response) {
        Log.i("TBM", "matches loaded");
        TurnBasedMatchBuffer matchBuffer = response.getMyTurnMatches();
        matchBuffer.close();

        response.getCompletedMatches().close();
        response.getTheirTurnMatches().close();
        response.getInvitations().close();
        response.close();
    }

}

LogCat Output:

03-15 21:16:04.594: I/googleApiClient(6066): connected
03-15 21:16:04.666: I/TBM(6066): load matches async
03-15 21:16:18.366: E/DataBuffer(6066): Internal data leak within a DataBuffer object detected!  Be sure to explicitly call close() on all DataBuffer extending objects when you are done with them. (com.google.android.gms.games.multiplayer.turnbased.TurnBasedMatchBuffer@a69f2d40)

onTurnBasedMatchesLoaded is never called. What am I doing wrong?

推荐答案

You have to register the ResultCallback

 Games.TurnBasedMultiplayer.loadMatchesByStatus(googleApiClient, TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN).setResultCallback(
        new ResultCallback<TurnBasedMultiplayer.LoadMatchesResult>()
        {
          @Override
          public void onResult(LoadMatchesResult result)
          {

          }
        });
查看更多