Android real-time multiplayer: onRoomCreated gets erratic STATUS_NETWORK_ERROR_NO_DATA

[亡魂溺海] 提交于 2019-12-04 06:23:43

问题


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

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

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

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

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.

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

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.

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.


回答1:


[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]: 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]

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();".

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

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



来源:https://stackoverflow.com/questions/35274996/android-real-time-multiplayer-onroomcreated-gets-erratic-status-network-error-n

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