Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turnbased matches disappear after loading for the first time

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!

like image 606
matsjoe Avatar asked Apr 22 '15 17:04

matsjoe


1 Answers

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.

like image 103
Mitchell Carroll Avatar answered Feb 17 '23 22:02

Mitchell Carroll