助手类中的Firebase返回空实例
这里助手类中的Firebase返回空实例,firebase,kotlin,firebase-authentication,Firebase,Kotlin,Firebase Authentication,这里FirebaseAuth.getInstance()总是返回null,我不知道为什么。如果我在像这样的活动中使用它 class FirebaseHelper { companion object { private var mAuth: FirebaseAuth? = null fun getInstance(): FirebaseAuth? { if(mAuth == null ){ m
FirebaseAuth.getInstance()
总是返回null,我不知道为什么。如果我在像这样的活动中使用它
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
}
}
}
它返回firebase实例。我不明白有什么区别。我试图不使FirebaseHelper.getInstance()方法成为静态的,但它也不起作用
有什么提示吗?如果您使用模拟器,请尝试使用真实设备。我没有使用模拟器如果您使用模拟器,请尝试使用真实设备。我没有使用模拟器
mAuth = FirebaseAuth.getInstance()
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
}
}
}