I'm using Google's Achievements API for the first time and have found it fairly simple to set-up. I got it up and running in about an hour, however, one thing I just can't figure out, is how to go about unlocking achievements when the user isn't signed in (or rather storing the fact that achievement x has been unlocked locally so it can actually be unlocked when the user next logs in).
My achievements are unlocking OK if the user is signed in.
Initially, when I was testing this without being logged in, I was getting a 'googleAPIClient is not connected yet' error popping up in my LogCat.
So I did something like this:
public void unlockAchievements(){
if (isSignedIn()){
Games.Achievements.unlock(getApiClient(), myAchievementID);
}
}
This obviously avoids the crash, but (again, obviously), doesn't unlock the achievement if the user isn't yet signed in.
Is there an 'official' way the handle this (I can't seem to find any mention of this in the doccumentation - although I may have missed it).
If there isn't, what would be a good way to do this?
I could do something like:
if (score>1000){
score1000Achievement = true; //Save this to SharedPreferences
}
And then later, do this:
onSignInSucceeded(){
if (score1000Achievement){
Games.Achievements.unlock(getApiClient(), myAchievementID);
}
}
However, this would run and attempt an unlock at every login, which, with multiple achievements and multiple users, would surely increase my API calls and therefore eat into my quota unnecessarily?
Grateful for any advise
Edit
Just found this on an Android Developers Site
An unlocked achievement means that the player has successfully earned the achievement. An achievement can be unlocked offline. When the game comes online, it syncs with the Google Play games services to update the achievement's unlocked state.
However, there seems to be no further mention of it and no example of how this is accomplished.
I did the same approach as you did, but I saved another boolean to know if the achievement was unlocked on Google play. Can't remember though, if the unlocking has a success-return value.