Android real-time multiplayer: onRoomCreated gets erratic STATUS_NETWORK_ERROR_NO_DATA
Asked Answered
L

1

0

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.

Livelong answered 8/2, 2016 at 16:55 Comment(0)
L
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).

Livelong answered 9/2, 2016 at 15:4 Comment(6)
How do you achieve waiting for the callback onleftroom() when onstop gets called? "So we are waiting AT LEAST the end of "onLeftRoom" (plus 3 sec, just in case) before trying to create a new room. "Heathenish
@skymedium: when "onStop" is called, the room is "left" (with .leave(...)) but we are NOT waiting for onleftroom() because it becomes useless to create a new room... only when one of the two players leaves the room (and the application keeps running) do we wait for onleftroom, because it is the signal that everything is done and over with this particular room.Livelong
I followed all your instructions and I still get the NETWORK_ERROR. Do you have another suggestions? Can you share the source of your answer?Heathenish
the problem (for us) was when a room had been created but NOT PROPERLY CLOSED (with .leave(...)) when you exit the application or when you try to create another one. Make sure that you wait "onLeftRoom" after leaving a room, to create a new one. DO NOT leave the room after onDisconnectedFromRoom. Unfortunately I cannot share our source, sorry.Livelong
Ok, sorry, this was not a valid answer... the problem is back again... except this time it's when the device didn't get access to Internet for some time, and when to app is launched the room creation fails (although Internet access has been validated in 2 different ways). This means that it's still imposible for us to release our game and 2 years of work is good for the garbage bin. PLEASE HELP!!!!Livelong
Same here. I have created a post on github. Response is pending.Heathenish

© 2022 - 2024 — McMap. All rights reserved.