TurnBasedMultiplayer - onTurnBasedMatchesLoaded does not get called

跟風遠走 提交于 2019-12-25 02:26:42

问题


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?


回答1:


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)
          {

          }
        });


来源:https://stackoverflow.com/questions/22429654/turnbasedmultiplayer-onturnbasedmatchesloaded-does-not-get-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!