Google Play Game Service - Unlocked Achievement Popup not shown

When I unlock an achievement, the “Achievement Unlocked” pop-up window does not appear, but the achievement is unlocked, as I see in the list of achievements.

I have already tried this solution, but it does not work.

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 will unlock these achievements:

  Games.Achievements.unlock(googleApiClient, "achievement id"); 

Thanks in advance!

+5
source share
1 answer

The games API is designed for one action, although you can use it in multiple instances. Have you had a chance to see the samples they provide on the GithHub page? They have some classes in BasicSamples / libraries / BaseGameUtils that may be useful.

You invoke the Builder method in your main action with this .

 new GoogleApiClient.Builder(this) //this being your MainActivity 

Then you install the Api client in the application class. Now that you are in your new GameOverActivity , the api client is trying to show an idea of ​​an activity that is no longer present on the screen. This has only a link to your MainActivity. You should not set the Application class variable for Api Client. This is also a bad practice because you are setting listener callbacks to action and may not be there by the time one of the callbacks is called.

Any activity that you want to interact with the game APIs must be obtained from the BaseGameActivity found in BaseGameUtils on GitHub. In each action, you will get a method called getApiClient() .

+3
source

Source: https://habr.com/ru/post/1210284/


All Articles