1

So I'm writing a java game with Eclipse that uses Google Play Game Services to handle my achievements. I have done everything as in the sample games provided by Google, with the exception that I have added GameHelper directly to my existing activity instead of using BaseGameActivity. Now I have a problem. If a player uses one device to unlock an achievement that actually affects the game, how can I make the other device spot the unlocked achievement?

With a bit of browsing I have found out that I should be using mHelper.getGamesClient().loadAchievements(OnAchievementsLoadedListener listener) and then use that onAchievementsLoaded (int statusCode, AchievementBuffer buffer) listener. The AchievementBuffer buffer seems to contain all the data I want.

Now the problem is that I have no idea how to use this listener. Where should I put it, should I call loadAchievements() or is it called automatically at sign in etc.

It would be great if somebody could help me with this :)

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Finnboy11
  • 986
  • 2
  • 15
  • 34

1 Answers1

3

Indeed, the Achievement buffer will contain all the data you want (if the statusCode returned is STATUS_OK). You can load the achievements "on-demand" from your activity (which extends BaseGameActivity per example) via:

getGamesClient().loadAchievements(new OnAchievementsLoadedListener() {
    @Override
    public void onAchievementsLoaded(int statusCode, AchievementBuffer buffer) {
        if (statusCode == GamesClient.STATUS_OK) {
            int achievementsCount    = buffer.getCount();

            [...]

        }
        buffer.close();
    }
});

And do not forget to close the buffer.

Aladin Q
  • 550
  • 5
  • 12
  • I already managed to do this in another way and was going to answer this question myself, but your answer is much more simple than mine. Thank you for adding the status check and buffer closing too, although I knew about those already :) – Finnboy11 Jul 01 '13 at 13:03