class FirebaseHelper {
companion object {
private var mAuth: FirebaseAuth? = null
fun getInstance(): FirebaseAuth? {
if(mAuth == null ){
mAuth == FirebaseAuth.getInstance()
}
return mAuth;
}
fun getCurrentUser(): FirebaseUser?{
return getInstance()?.currentUser
}
}
}
这里FirebaseAuth.getInstance()
总是返回null,我不明白为什么。如果我在
mAuth = FirebaseAuth.getInstance()
它返回firebase实例。我没有得到什么区别。我试图不将FirebaseHelper.getInstance()方法设为静态,但它也不起作用。
任何提示?
答案 0 :(得分:2)
class FirebaseHelper {
companion object {
private var mAuth: FirebaseAuth? = null
fun getInstance(): FirebaseAuth? {
if(mAuth == null ){
// here you should use "=" instead of "=="
mAuth == FirebaseAuth.getInstance()
}
return mAuth;
}
fun getCurrentUser(): FirebaseUser?{
return getInstance()?.currentUser
}
}
}