在使用的onCreate isSignedIn? [谷歌Play业务] [英] Using isSignedIn in onCreate? [Google Play Service]

查看:154
本文介绍了在使用的onCreate isSignedIn? [谷歌Play业务]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我想让用户,所以我使用谷歌播放服务与他们的谷歌帐户登录。这工作 - 他们可以登录和注销。我也想看看,如果用户在的onCreate 方式签署当我通过从一个活动到另一个。我试图使用谷歌发挥服务,这一点,但在的onCreate 方式它总是返回false isSignedIn功能(因为谷歌发挥业务触发上的在onStart )。

In my application i want to let users sign in with their google account so i am using google play services. This works - they can login and logout. I also want to find out if the user is signed in the onCreate method when i pass from one activity to another. I am trying to use Google play services isSignedIn function for this but on onCreate method it always return false (because google play service trigger on onStart).

为什么我需要它?

由于,我有两个登录选项。一个是谷歌帐户中的另一个是我自己的登录面板。我想知道这是在谷歌wtih用户登录或我的系统或不上的的onCreate 。所以,我会给我的方向流动。

Because, i have two login option. One is google account another is my own login panel. I want to know that is user sign in wtih google or my system or not on onCreate. So i will give direction my flow.

我怎样才能achive这个还是有其它的建议?

How can i achive this or do you have an alternative suggestion ?

感谢您的答案。

推荐答案

这是由于活动的生命周期。每次活动进入后台,将获得的onStop 。 Play游戏API要求您断开当这种情况发生。当活动回来推向前台,它得到在onStart ,然后GameHelper将尝试重新建立连接。在此之前, isSignedIn 将返回。当连接恢复(这应该是非常快的,如果用户已经登录),在 onSignInSucceeded 的回调将被调用,从点isSignedIn 将返回真正

This is due to the Activity lifecycle. Every time an Activity goes into the background, it will get onStop. The Play Games API requires you to disconnect when this happens. When the Activity comes back into the foreground, it gets onStart, and then GameHelper will attempt to reestablish the connection. Until this happens, isSignedIn will return false. When the connection is restored (which should be very fast if the user had already signed in), the onSignInSucceeded callback will be called and from that point on isSignedIn will return true.

这是不可能知道的,在的onCreate 时,登录是否会成功。相反,你应该等待或者 onSignInSucceeded onSignInFailed 。这是保证这两个回调的一个活动进入前台后不久将调用。

It's impossible to know, on onCreate, whether or not the sign-in will succeed. Instead, you should wait for either onSignInSucceeded or onSignInFailed. It is guaranteed that one of those two callbacks will be called shortly after the Activity comes into the foreground.

在这一点上,你可以决定做什么,因为这将是清楚用户是否与谷歌+登录。

At that point, you can decide what to do, because it will be clear whether or not the user is signed in with Google+.

这篇关于在使用的onCreate isSignedIn? [谷歌Play业务]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆