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

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

问题描述

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

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 API 说:

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:

  • 在注册监听器之后
  • 当用户登录时
  • 当前用户退出时
  • 当前用户发生变化时
  • 当前用户的令牌发生变化时(注意这已被移除并移至单独的侦听器,请参阅FirebaseAuth.IdTokenListener)
  • 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天全站免登陆