I have tried to follow to Google documentation for Google Play Services but that's impossible, because Google documentation is the worst ever.
Anyway, I manged to setup project and add Google Play Services in my app, but I don't know how to keep connected state of player when user changes activity.
I have MainActivity, where extend BaseGameActivity, and then user click on button Play, I open GameActivity, where I play game, and when I finish game I want to submit score to Google Play Services Leaderboard, but I can't because it seems that I am not connected.
I extend MyActivity with BaseGameActivity
public class MainActivity extends BaseGameActivity
Then I on GameActivity extend this:
public GameActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
And then on onCreate use this:
// Create the Google Api Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
// add other APIs and scopes here as needed
.build();
And then when I finish game I try to submit score, but it seems that I am not connected.
if(mGoogleApiClient.isConnected()){
Games.Achievements.unlock(mGoogleApiClient,
getString(R.string.app_name));
Games.Leaderboards.submitScore(mGoogleApiClient,
getString(R.string.number_guesses_leaderboard),
clickCounter);
}