In my application, i have in game helper(i want log in on button click):
// Whether to automatically try to sign in on onStart(). We only set this
// to true when the sign-in process fails or the user explicitly signs out.
// We set it back to false when the user initiates the sign in process.
boolean mConnectOnStart = false;
In my MainActivity (extends BaseGameActivity), after login button click i call:
beginUserInitiatedSignIn();
Of course now isSignedIn() returns true.
But when I go to next Activity (aslo extends BaseGameActivity): isSignedIn() return false.
I can of course call beginUserInitiatedSignIn() on my next Activity, but i don' t want it. In my app user can be logged in, but not have to. So if user not logged in at my mainActivity i don' t want show login form on next activity.
Edit: For this moment my solution is to create static variable and set it when i leave my main activity for ture if isSignedIn() and call beginUserInitiatedSignIn() on next activity only when this variable is true. Is it any better, automatic solution ?
There's two types of sign in:
- The user initiated sign in which shows the Google Play Games logo and requires the user to approve access, etc.
- Silent sign in (which
BaseGameActivity
does in itsonStart
call) - this automatically attempts to sign in and, if the user has already signed in, does the same callback as if you had gone through the user initiated sign in flow.
Therefore you do need to wait for the sign in callback before attempting any Google Play Games related calls in each and every activity.
Note that recently (4 days ago on Feb 18, 2014), the BaseGameUtils library for Android was updated to use the new Google Api Client model, which allows you to do read calls before being signed in (where they will automatically wait until sign in before attempting to process). As the Google Api Client gives a number of other benefits (such as improved sign in reliability), you should update to the latest BaseGameUtils
if you haven't already.
来源:https://stackoverflow.com/questions/21962210/google-play-game-services-not-signed-in-on-next-activity