OnRealTimeMessageSent回调没有被可靠地触发?

时间:2013-08-06 10:16:40

标签: android google-play-games

使用Google Play游戏服务,我正在尝试实施一个回复,以便在发送邮件时出现问题,然后我需要解决它(因为每个玩家将其出价“转移”给下一个玩家,所有其他玩家都需要看看通过竞标的玩家是什么意思

我想我会尝试使用以下内容为该轮消息实例化一个RealTimeReliableMessageSentListener,以便我可以判断消息是否被所有人发送和接收:

(我将调用返回的tokenID添加到ArrayList,然后检查删除每个tokenID,因为它返回以跟踪收到来自此轮的所有消息的时间)

@Override
    public void sendReadyToPlay() {
        dLog("Sending ReadyToPlay");
        // Broadcast that I'm ready, and see that they are ready
            if (!mMultiplayer){
                return; // playing against computer
            }
            // First byte in message indicates whether it's a final score or not
            mMsgBuf[0] = (byte) ('R');
            readyToPlayTokens.clear();
            // Send to every other participant.
            for (Participant p : mParticipants) {
                dLog("Participant:" + p.getParticipantId());
                if (p.getParticipantId().equals(mMyId)) {
                    continue;}
                if (p.getStatus() != Participant.STATUS_JOINED){
                    continue;
                }

                readyToPlayTokens.add(mHelper.getGamesClient().sendReliableRealTimeMessage(new RealTimeReliableMessageSentListener() {

                    @Override
                    public void onRealTimeMessageSent(int statusCode, int tokenId, String recipientParticipantId){
                        dLog("onRealTimeMessageSent number two and size is: " + readyToPlayTokens.size());
                        if(readyToPlayTokens.contains(tokenId)){
                            readyToPlayTokens.remove(tokenId);
                        }

                        dLog("onRealTimeMessageSent number two and size is: " + readyToPlayTokens.size());
                        if (statusCode != GamesClient.STATUS_OK) {
                                mGHInterface.onRealTimeMessageReceived("RTPProblem:" + recipientParticipantId);
                            } else if (readyToPlayTokens.size() == 0) {
                                mGHInterface.beginRound();
                            }

                    }
                }, mMsgBuf, mRoomId,  p.getParticipantId()));
                dLog("sent to:" +  p.getParticipantId());
            }
        }

我几乎每次都能看到从一个设备到另一个设备的消息,所以我可以看到消息正在通过,但是,RealTimeReliableMessageSent监听器只被触发了大约50-60%的时间,这不是不太可靠! :)

任何人都可以看到我可能做错了让听众无法可靠地开除吗?

1 个答案:

答案 0 :(得分:0)

可能是因为您使用的是匿名内部类,尝试以不同的方式使用,例如实施您的活动RealTimeReliableMessageSentListener

相关问题