Android real-time multiplayer: onRoomCreated gets erratic STATUS_NETWORK_ERROR_NO_DATA

后端 未结 1 528
孤城傲影
孤城傲影 2021-01-27 05:30

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 developmen

相关标签:
1条回答
  • 2021-01-27 06:10

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

    0 讨论(0)
提交回复
热议问题