Firebase authentication taking too long from Android Device

淺唱寂寞╮ 提交于 2019-12-07 14:37:18

问题


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?


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/39669921/firebase-authentication-taking-too-long-from-android-device

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