Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Game Service - Unlocked Achievement Popup not shown

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!

like image 537
ToasteR Avatar asked Jan 02 '15 21:01

ToasteR


2 Answers

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().

like image 65
kevskree Avatar answered Oct 30 '22 20:10

kevskree


I had to do the following:

GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
like image 24
thiagolr Avatar answered Oct 30 '22 21:10

thiagolr