Firebase身份验证从Android设备花费的时间太长 [英] Firebase authentication taking too long from Android Device

查看:62
本文介绍了Firebase身份验证从Android设备花费的时间太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase向不同的提供商(google,facebook和电子邮件)注册和登录用户.我已经使用此功能三个月了,到目前为止一切正常.但是,此刻,当我在安装该应用程序后进行首次登录时,需要花费10秒钟以上的时间.我已跟踪了行为,发现该侦听器导致了延迟.

I am using Firebase to register and log users with different providers (google, facebook and email). I have been using this functionality for three month and so far it has worked fine. However, at this moment, when I make the first login after installing the app, it takes more than 10 seconds. I have traced the behavior and I find this listener is causing the delay.

private FirebaseAuth firebaseAuth;
...    
firebaseAuth.signInWithCredential(credential).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
        @Override
        public void onSuccess(AuthResult authResult) {
            // This function is called after more than 10 seconds
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            //
        }
    });

关于为什么需要太长时间的任何想法?有什么办法可以使我对该功能进行更深入的跟踪,以找到问题的确切根源?

Any ideas about why it takes too long? Is there any way I can make a deeper trace of this function to find the exact source of the problem?

推荐答案

此特定的侦听器(onSuccess)正在从Firebase服务器启动回调,这可能是造成延迟的原因.就像在远处的墙壁上扔一个球,然后等待它反弹之前,才可以接住.

This particular listener(onSuccess) is initiating a callback from Firebase server which is probable cause of that delay. Its like throwing a ball at a distant wall and then waiting for it to rebound before you can catch.

这将监听您的登录事件,即使登录成功,它也会等待firebase响应以明确确认登录成功.我个人觉得您不需要此回调检查.因为您可以轻松检查实际功能中的错误和成功登录.

This will listen to your sign in events and even on successful sign in it will wait for firebase response to explicitly confirm that sign in has been successful. I personally feel you don't need this callback check. Because you can easily check for errors and successful sign-ins in your actually functions.

您应该使用.onCompleteListener并进行检查.我希望这可以使代码逻辑有些相似,并且仍然可以提供更好的结果

you should rather use .onCompleteListener and check. I hope that will keep the code logic somewhat similar and still give better results

这篇关于Firebase身份验证从Android设备花费的时间太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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