Google Play Game Service - Unlocked Achievement Popup not shown
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()
.
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);