Reassign Google Play login between actions

I thought it was going to be simple, but I was going around in circles trying to figure out how to keep the user registration in between Activities

.

I have "Main" and "Details" Activity

. The user enters into Google Play Services

the "Main" Activity

and I want to submit the results and leaderboard data in the "Details" Activity

.

I inherit from BaseGameActivity

both in Activities

and using:

 mGoogleApiClient = getApiClient();

      

in Details, however, when I call isConnected

it always returns false

.

I even tried to copy all the login / callback code from "Main" Activity

, but it still doesn't detect that the user is logged in.

This post suggests not to use BaseGameActivity

and pass GameHelper

with singleton

:

How can I use BaseGameActivity.getApiClient () in multiple activities?

Not sure what is the correct approach.

+2


source to share


1 answer


The easiest way to do this is to force both actions to create a separate instance of the api client. The connection state is shared internally, so you don't need to worry about how to bypass the client and handle the callbacks that can occur when the activity is not active and the player will only enter your main activity.

Extending your activity from BaseGameActivity is really no longer needed (for an entertaining explanation: Death of BasegameActivity . What you need to do implements two interfaces that handle the initialization of the GoogleAPIClient:



public class MainActivity extends Activity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {
        }

      

To implement them refer to the samples and the doc: https://developers.google.com/games/services/android/init

+3


source







All Articles