Google Play Game Services - not signed in on next activity

元气小坏坏 提交于 2019-12-06 12:20:28

问题


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 ?


回答1:


There's two types of sign in:

  1. The user initiated sign in which shows the Google Play Games logo and requires the user to approve access, etc.
  2. Silent sign in (which BaseGameActivity does in its onStart 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!