3

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.

Teyam
  • 7,686
  • 3
  • 15
  • 22
Chandan Wadhwa
  • 196
  • 2
  • 13

1 Answers1

0

If you happen to be using BaseGameActivity, extending your activity is no longer needed. Instead, use BaseGameUtils library to resolve connection errors and display dialogs.

Try initializing GoogleApiClient by implementing the GoogleApiClient.ConnectionCallbacks and GoogleApiClient.OnConnectionFailedListener interfaces. See this documentation for more information.

import com.google.android.gms.*;
import com.google.example.games.basegameutils.BaseGameUtils;

public class MyGameActivity extends Activity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

For additional insights, you may want to check the following :

Teyam
  • 7,686
  • 3
  • 15
  • 22