Android实时多人游戏:onRoomCreated不稳定STATUS_NETWORK_ERROR_NO_DATA [英] Android real-time multiplayer: onRoomCreated gets erratic STATUS_NETWORK_ERROR_NO_DATA

查看:115
本文介绍了Android实时多人游戏:onRoomCreated不稳定STATUS_NETWORK_ERROR_NO_DATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:onRoomCreated返回STATUS_NETWORK_ERROR_NO_DATA的次数为5%,无缘无故。

Problem: onRoomCreated returns STATUS_NETWORK_ERROR_NO_DATA 5% of the times, for no reason that we can figure out.

游戏在大约16个月的开发过程中运行良好(没有清单或Google Play控制台中缺少权限的问题),但从Google Play服务29开始(即可能 ...可能无关),这种不可预测的行为开始了,并且它阻止了任何进一步的尝试来创建一个房间(即使重新启动游戏后,错误的statusCode也会再次出现)。

The game worked well for about 16 months of development (no problem of missing "permissions" in the manifest or the Google Play Console) but starting with Google Play Service 29 (that's "allegedly"... it could be unrelated), this unpredictable behaviour started, and it is blocking any further attempt to create a room (same wrong statusCode over again, even after restarting the game).

唯一使其恢复工作的方法是在10-15分钟后重新启动游戏

The only way to make it work again is either to restart the game after 10-15 minutes or to restart the device (usually works but not always).

在3种不同的设备上都存在相同的问题(此处没有仿真器)。

The problem is the same on 3 different devices (no emulators here).

关于这个问题(在SO和其他地方)的发现是,它可能与尝试创建新的问题之前没有离开房间(RealTimeMultiplayer.leave(...))有关。因此,在创建新房间之前,我们至少要等到 onLeftRoom的结尾(加上3秒,以防万一)。毫无用处。

What we found about this problem (on SO and elsewhere) is that it could be related to NOT leaving the room (RealTimeMultiplayer.leave(...)) before trying to create a new one. So we are waiting AT LEAST the end of "onLeftRoom" (plus 3 sec, just in case) before trying to create a new room. To no avail.

显然,我们遵循以下推荐的准则:在onCreate上实例化GoogleApiClient,在onStart上实例化.connect,在onStop上实例化.disconnect(即使.connect正在进行中) )...

Obviously we are following the recommended guidelines: instantiate GoogleApiClient in onCreate, .connect in onStart, .disconnect in onStop (even if .connect is on its way)...

还要注意,因为它应该是 NETWORK_ERROR,所以在每次尝试创建Internet连接之前,我们都在验证Internet连接(使用ping操作)

Also notice that, because it's supposed to be a "NETWORK_ERROR", we are validating the Internet connection (with a ping) before each attempt to create a room.

请,如果您有关于此问题的任何信息,或者您知道在此statusCode之后如何使Google Play创建房间而无需重新启动设备,请让我们知道,因为直到那时我们的发布日期都将永远推迟。非常感谢。

Please, if you have ANY info about this issue, or if you know how to make Google Play create a room after this statusCode WITHOUT restarting the device, please let us know because until then our release date if forever postponed. Thanks a lot.

推荐答案

[更新2]:应用已被重写,以停止自动创建房间(因此请求频率较低),和...什么都没有...仍然是相同的错误/问题/您为它命名...一遍又一遍...然后Google Play更新了应用 Google Play游戏(也许还有服务),有点工作:在2周内只有一个STATUS_NETWORK_ERROR_NO_DATA ...现在我要睡2个月,因为我[已编辑]。

[UPDATE 2]: app was rewritten to stop making automated room creations (hence less frequent requests), and... nothing... still the same bug/problem/you-name-it ... over and over ... then Google Play updated the app "Google Play Games" (and maybe "services") and it kinda worked: only one STATUS_NETWORK_ERROR_NO_DATA in 2 weeks... now I'm going to sleep for 2 months because I'm [redacted].

[UPDATE]: 这篇文章,STATUS_NETWORK_ERROR_NO_DATA用于限制频率的请求。因为我们确实实现了房间的创建和关闭的自动化,所以这可能是最终的答案。无论验证与否,我都会再次更新。
我留下了这个答案的其余部分,因为,尽管它不是直接相关的,但不关闭房间也会引起错误。[END OF UPDATE]

[UPDATE]: according to this post, STATUS_NETWORK_ERROR_NO_DATA is used to limit the frequency of requests. Because we do automate room creations and closings this could be the definitive answer. I'll update once again when it's validated or not. I leave the rest of this answer because, although it's not directly related, not closing rooms also induces errors.[END OF UPDATE]

以下是答案这种不可预测的行为(并非来自SO,但您中的某些人可能仍然有兴趣):在 onStart和 onStop中,对Google Play服务(无论是否使用mG​​oogleApiClient)的所有调用/请求都必须在超级之前进行。 onStart();

Here's the answer to this unpredictable behavior (didn't come from SO but some of you might still be interested): in "onStart" and "onStop", all calls/requests to Google Play Services (with mGoogleApiClient or not) must be made BEFORE "super.onStart();" and "super.onStop();".

否则,在 super.onStop();之后会发生什么。将在结束之前被中断(设备的速度和负载增加了一些随机性),这意味着对 .leave打开房间的任何调用都会失败,然后阻止创建新房间(因此STATUS_NETWORK_ERROR_NO_DATA错误)。

Otherwise what comes after "super.onStop();" will be interrupted before it's over (with some randomness added by device's speed and load), which means that any call to ".leave" an open room will fail, and then prevent the creation of a new room (hence the STATUS_NETWORK_ERROR_NO_DATA error).

还要注意,变量mGoogleApiClient不应声明为静态,请记住调用 mGoogleApiClient.disconnect();在 onStop中(建议在其他地方使用 ButtonClicker示例时,则不会这样做)。

Also notice that the variable mGoogleApiClient should not be declared as static, and remember to call "mGoogleApiClient.disconnect();" in "onStop" (the example "ButtonClicker" doesn't do that when it's recommended elsewhere).

这篇关于Android实时多人游戏:onRoomCreated不稳定STATUS_NETWORK_ERROR_NO_DATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆