目前正在研究在Android(MVP)中使用Firebase Auth。 我的流程大致如下:
Activity > Presenter > Interactor > AuthHelper
Activity < Presenter < Interactor < AuthHelper
Auth Helper类是唯一直接与FirebaseAuth
实例交互的类。我的问题是在这种情况下,AuthStateListener如何工作:
- Interactor has
FirebaseAuth.AuthStateListener
Interactor initializes Auth Helper class, passing the
AuthStateListener
class MyInteractor implements FirebaseAuth.AuthStateListener { FirebaseAuth.AuthStateListener listener; public MyInteractor(){ MyHelper myHelper = new MyHelper(this); listener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { Log.d("TAG", "onAuthStateChanged called"); } }; } public void signOut(){ myHelper.signOut(); } }
Helper passes the
FirebaseAuthInstance
to the listenerclass MyHelper { private static FirebaseAuth mAuth; public MyHelper(FirebaseAuth.AuthStateListener listener){ mAuth = FirebaseAuth.getInstance(); listener.onAuthStateChanged(mAuth); } public void signOut(){ mAuth.signOut(); } }
myHelper.signOut()
is called
期望结果:
在交互器中,onAuthStateChanged()
将被触发。
收到的结果:
onAuthStateChanged()
未被触发。
我尝试了另一种方法,在调用signOut()
后传递了mAuth
:
public void signOut(){
mAuth.signOut();
listener.onAuthStateChanged(mAuth);
}
这会触发
onAuthStateChanged
。这里有什么我漏掉了吗?
MyHelper
类),从那个调用中,我期望触发 interactor 中的onAuthStateChanged()
。 - AL.