我的 LoginActivity 中有我的 onCreate,如下所示:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
if(currentUser!= null) {
currentUserId = currentUser.getUid();
}
但是我的变量,当我第一次安装我的应用程序时,currentUserId 为空。为什么?我该如何解决它?
当我第一次安装我的应用程序时,currentUserId 为空...为什么?
这是预期的行为,因为用户第一次安装/打开应用程序时未经过身份验证。 FirebaseAuth 的获取当前用户() https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth#getCurrentUser()方法:
返回当前登录的Firebase用户 https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser or null如果没有的话。
如上所示,如果返回 null,则表明用户未通过身份验证。要获取实际的 FirebaseUser 对象,请使用以下命令对用户进行身份验证可用选项/提供商之一 https://firebase.google.com/docs/auth,并且该对象将不再为空。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)