问题
When I unlock a achievement the "Achievement unlocked" popup is not popping up but the achievement is unlocked as I can see in the achievement list.
I've already tried this solution but it is not working.
I initialize the GoogleApiClient like this in my MainActivity:
gac = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
app.setGoogleApiClient(gac);
gac.connect();
In my "Game over Activity" I do the following:
ApplicationClass app = (ApplicationClass) getApplication();
googleApiClient = app.getGoogleApiClient();
... and I unlock achievements like this:
Games.Achievements.unlock(googleApiClient, "achievement id");
Thanks in advance!
回答1:
The Games API is designed for a single Activity although you can use it in multiple. Have you had a chance to look at the Samples they provide at GithHub pages? They have some classes under BasicSamples/libraries/BaseGameUtils that might be helpful.
You are calling the Builder method on your main activity with this
.
new GoogleApiClient.Builder(this) //this being your MainActivity
Then you are setting the Api client to the application class. Now, when you're in your new GameOverActivity
, the api client is trying to show a view on an activity that is no longer present on screen. It only has a reference to your MainActivity. You should not set a variable on the Application class for the Api Client. This is also bad practice because you set the listener callbacks to the activity and may not be there anymore by the time one of the callbacks is invoked.
Any activity you want to interact with the Games API should derive from BaseGameActivity
found in the BaseGameUtils
on GitHub. In each activity you will have a method called getApiClient()
.
来源:https://stackoverflow.com/questions/27748866/google-play-game-service-unlocked-achievement-popup-not-shown