Google leaderboard submitscore error:GoogleApiClient must be connected

Viewed 467

Getting problem in saving score in leaderboard.

In my case first in login screen is which user login using google. Second screen is game activity and after finishing game i want score to be save in leaderboard.

I am using below code for GoogleApiClient initialization :-

mGoogleApiClient = new GoogleApiClient.Builder(this)

        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Games.API).addScope(Games.SCOPE_GAMES)
        .build();
setContentView(R.layout.activity_game);

For saving game score :-

 Games.Leaderboards.submitScore(mGoogleApiClient, getResources().getString(R.string.leaderboard_id), millis);

But it is saying:- GoogleApiClient must be connected.

But when a add sign in api to google client like below it is saying you can not use Games.Api with Sign_in_api.

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this , this )
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();

Basically my question is how can i connect GoogleApiClient in my secound activity so that i can use Games.Leaderboards.submitScore to save game score.

Any kind of help will be appreciated.

1 Answers
Related