24

I'm developing a game for Android using the Google Play Services for creating a turnbased match.

At first everything was fine I load the turnbased matches for the signed in user using

Games.TurnBasedMultiplayer.loadMatchesByStatus(getApiClient(),
        new int[]{TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN,
                TurnBasedMatch.MATCH_TURN_STATUS_THEIR_TURN,
                TurnBasedMatch.MATCH_TURN_STATUS_INVITED,
                TurnBasedMatch.MATCH_TURN_STATUS_COMPLETE})
        .setResultCallback(this);

It always loaded all matches that are any of the given states. But since last weekend the callback is called but there are no matches, as I'm not participating in any match (Status response is OK). I deleted the cache of Google Play Services on my phone and rebooted the device. At that moment all the matches were shown again until the next time I opened the app. Again all matches were missing. Once I start a new match the match keeps showing up with the above method (refreshing the list) until I close the app. At the next launch that match is also gone.

I have to say the game is not published yet but in a test phase on the Google Play Developer Console. I found the same issue on an emulator. It ran fine for days but suddenly got the same problem as my real device (with a later build so it is not that a single change of code causes this).

Did anyone else notice this behaviour or has an idea on how to resolve it?

Might it be related to having multiple apps connected to one game? I had two apps signed with debug certificates connected and this afternoon added one for a signed apk. When I used the signed apk it worked again until I deployed a new test app (debug signed). After switching back to the signed apk the bug is still around.

As nobody seems to know the answer let me rephrase the question. Should I cache TurnBasedMatches myself on the device? I just deleted the play services cache again and reopened my app. Result? A list of hundreds of games (since I have to start a new game every time while testing...)

My code to handle the loadMatchesResult

@Override
public void onResult(TurnBasedMultiplayer.LoadMatchesResult loadMatchesResult)
{
    showToast("GotMatches status: " + loadMatchesResult.getStatus().getStatusCode());

    //add matches to listview (only caching matchId, no references to turnbasedmatch)

    loadMatchesResult.getMatches().getMyTurnMatches().close();
    loadMatchesResult.getMatches().getInvitations().close();
    loadMatchesResult.getMatches().getTheirTurnMatches().close();
    loadMatchesResult.getMatches().getCompletedMatches().close();
    loadMatchesResult.release();

}

Found another interest point.. it starts to look like the issue occurs when deploying a new apk to the device... Once I deploy a new apk (either by install alpha version from google play or directly debug version from Android Studio) the matches are gone. When I don't change the apk I can reboot my phone/close the app and it works fine...

Issue also occurs if I update the app through the play store... There should be more people having this problem!

Evin1_
  • 12,292
  • 9
  • 45
  • 47
matsjoe
  • 1,480
  • 12
  • 17
  • 2
    I have a very similar problem with my turn-based game. The turn based matches often disappear when beta-testers update my app from the google play store. Same thing happens when I install a new version of the app on my device during development – tron May 06 '15 at 20:16
  • 1
    There is an issue open at github at https://github.com/playgameservices/android-basic-samples/issues/141 . Someone told to look into it 2 weeks ago but no other updates.. Personally I already totally removed google play games and switched to another (custom) backend – matsjoe May 18 '15 at 08:30
  • @matsjoe Ya I already saw that thread but the problem is not resolved. I am nearly done with my app using google play game services. Unfortunately, I don't have the time or money to switch to another backend. – user2456977 May 18 '15 at 13:12
  • @matsjoe Is it your own backend or a publicly available backend? We also consider switching. Even though we prefer not to, the lack of support may force us to. – tron May 21 '15 at 16:42
  • I started to use Parse it is not a plug and play framework for multiplayer matches but I managed to switch in about 2 weeks – matsjoe May 21 '15 at 20:47
  • There was a bug that reset the matches when a new apk was installed. If you have the latest Play Games app, it should be resolved. – Clayton Wilkinson Jul 01 '15 at 13:46

2 Answers2

1

Gotten from https://developer.android.com/reference/com/google/android/gms/common/api/PendingResult.html#setResultCallback(com.google.android.gms.common.api.ResultCallback)

After the result has been retrieved using await() or delivered to the result callback, it is an error to attempt to retrieve the result again. It is the responsibility of the caller or callback receiver to release any resources associated with the returned result. Some result types may implement Releasable, in which case release() should be used to free the associated resources.

After you retrieve the result, an error is given when you try to get the results again, until you free the resources associated with the returned result, which is why clearing the cache works to make them visible again. You need to either access the device's cache and display results from there as well, or clear the associated resources (within the program) whenever you want to access the results again.

Mitchell Carroll
  • 479
  • 5
  • 13
  • I assume this "error" is given when you try to use a DataBuffer after releasing it? Or does this mean a match is only returned once with Games.TurnBasedMultiplayer.loadMatchesByStatus(). Which won't make sense as it still shows up after a refresh. Might be worth mentioning it that the matches also won't display in the play games UI – matsjoe May 03 '15 at 10:06
  • I am having a similar problem. Whenever I run my application from Android Studio, I lose all my saved games. This started happening last week all of a sudden. – user2456977 May 03 '15 at 10:47
  • I will try to figure out what happens if I update the app through Google play. if the problem only occurs during development I can work around it by emptying the cache manually (far from perfect...) but if it happens with google play updates also it is an absolute no go – matsjoe May 03 '15 at 12:05
  • 1
    Same problem when updating using the play store.. this really blocks me from releasing my app.. – matsjoe May 03 '15 at 13:56
  • My guess is that it doesn't transmit the same data repeatedly to cut down on data costs, and also to protect against attacks, if it detects the data on your device, it only sends what you don't have yet. If you're displaying only what's given in the callback, you'll only have new data, not matches that have already been shown. In order to see what's already been shown, you either need to clear the data before the callback, or access the data that's in the device's cache. – Mitchell Carroll May 04 '15 at 02:32
  • 1
    If that was the case you would expect the Game Services view to show the data correctly, which it doesn't. It seems to me that there is a bug somewhere in the playservices lib when updating an apk – matsjoe May 04 '15 at 10:47
  • Game Services view? What do you mean by this? If you're accessing this from the same device you're using to test the app, then the same error might appear, depending on whether or not the results returned by the callback are hidden from other apps. If they aren't, then a similar call is likely being made whenever you open the other view, resulting in the same behavior. – Mitchell Carroll May 04 '15 at 17:10
  • To me this seems like a Play Game Services bug. I had no problems for months, then suddenly the issue appeared a few weeks ago. It seems to me like Google Play Game services gets out of sync with the google servers, probably because the match cache on the device is accidentally deleted, but the 'last sync' time stamp not. Because if an opponent takes a turn in a match missing from my device, the match will reappear on my device. I have been looking for a place to file a bug report, but found none. – tron May 06 '15 at 20:38
  • Exact same for me :) If the opponent takes his turn the data is back for me. I opened an issue at github (https://github.com/playgameservices/android-basic-samples/issues/141) you might to comment there that multiple people have the same issue – matsjoe May 06 '15 at 22:51
0

I had the same problem until I found "Saved Games" in my Developer Console:

  1. Go to Game Services -> Game Details -> Saved Games
  2. Set the item to "On"

Saved Games item in the Developer Console

This should solve your issue.

halfer
  • 19,824
  • 17
  • 99
  • 186
Paul Spiesberger
  • 5,630
  • 1
  • 43
  • 53
  • 1
    Unfortunately that doesn't work for me. I still have the problem despite having Saved Games turned on. – tron May 17 '15 at 20:03
  • We are also having some drawbacks here. A update over the Play Store seems to keep the games, but not during the development. Sometimes they also stay, weird – Paul Spiesberger May 18 '15 at 13:43