Firebase AuthStateListener如何工作? [英] How does the firebase AuthStateListener work?
问题描述
我正在使用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?
推荐答案
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屋!