Firebase AuthStateListener如何工作? [英] How does the firebase AuthStateListener work?

查看:79
本文介绍了Firebase AuthStateListener如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用firebase开发用于用户管理和身份验证的android应用.我想知道何时调用身份验证状态侦听器以及它如何工作,因为在我的应用程序中,我有一个与此相关的错误.

I am developing an android app using firebase for user management and authentication. I was wondering when the auth state listener gets called and how it works, as in my app I have a bug related to this.

这是我的android应用中的一个示例:

Here is an example of one in my android app:

mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // Sign in logic here.
                }
            }
        };

AuthStateListener如何工作以及何时调用?

How does the AuthStateListener work and when does it get called?

推荐答案

作为Firebase

As the Firebase API says:

AuthStateListener .

AuthStateListener is called when there is a change in the authentication state.

OnAuthStateChanged 在身份验证状态更改时在UI线程中被调用:

OnAuthStateChanged gets invoked in the UI thread on changes in the authentication state:

  • Right after the listener has been registered
  • When a user is signed in
  • When the current user is signed out
  • When the current user changes
  • When there is a change in the current user's token (Notice this has been removed and moved to a separate listener, see FirebaseAuth.IdTokenListener)

这篇关于Firebase AuthStateListener如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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