java - 我如何使用这个新的监听器

标签 java android google-play-services

我正在开发一款回合制多人游戏 Android 应用程序。

最初,我必须实现 TurnBasedMultiplayerListener 并覆盖 onTurnBasedMatchInitiated 但现在该接口(interface)已弃用,我需要使用 this listener

问题是,我不知道如何使用它。我已经让我的类实现了接口(interface),并且覆盖了这些方法。

然后我创建一个turnBasedGame,如下所示...

PendingResult<InitiateMatchResult> f =
    Games.TurnBasedMultiplayer.createMatch(gApiClient, tbmc);

现在我想我必须说f.setResultCallback(...)但我不知道要在里面放什么。

有什么建议吗?

最佳答案

您需要提供一个实现 ResultCallback 作为参数的类。

public void MatchInitiatedCallback implements ResultCallback {

    @Override
    public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) {
        // Check if the status code is not success;
        if (result.getStatus != GamesStatusCodes.STATUS_OK) {
            showError(statusCode);
            return;
        }

        TurnBasedMatch match = result.getMatch();

        // If this player is not the first player in this match, continue.
        if (match.getData() != null) {
            showTurnUI(match);
            return;
        }

        // Otherwise, this is the first player. Initialize the game state.
        initGame(match);

        // Let the player take the first turn
        showTurnUI(match);
    }
}

引用:https://developers.google.com/games/services/android/turnbasedMultiplayer#selecting_players_with_the_default_user_interface

关于java - 我如何使用这个新的监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21780525/

相关文章:

JavaFX:获取 ComboBoxTableCell 的 ComboBox

java - 在 Eclipse 中计算行号

android - jquery focus() 在移动设备(android)中不起作用,phonegap-cordova

java - 完成,重新加载 Activity

android - SMS Retriever Api 的播放服务版本问题

java - 为什么这个socket程序不传输数据?

java - mvn 无法从终端在自定义位置执行 testNG 类

android - 在循环数组之前等待 AsyncTask 完成

android - Google Play 服务 - SafeParcelable 在哪里?

android - 如何使用 play services 8.3 使用新的 google 登录获取访问 token ?