Google Play Game Service - Unlocked Achievement Popup not shown

自闭症网瘾萝莉.ら 提交于 2019-12-09 13:11:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!