注销匿名身份验证后,FirebaseUser不为空 [英] FirebaseUser is not null after anonymous authentication is signed out
问题描述
我的应用程序中有2个活动.我还有一个登录按钮,单击该方法时将被称为:
I have 2 activities in my app. I also have a sign-in button that when clicked this method is called:
private void signIn() {
firebaseAuth.signInAnonymously().addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
if (firebaseUser != null) {
goToSecondActivity();
}
}
});
}
这是我的goToSecondActivity()
方法:
private void goToSecondActivity() {
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
finish();
}
在onStart()
中的官方文档中指定. ,我像这样检查firebaseUser
对象是否为空:
As specified in the official doc, in onStart()
, I check the firebaseUser
object for nullity like this:
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
if (firebaseUser != null) {
goToMapActivity();
}
在第二个活动中,我试图像这样获取用户的uid:
In the second activity I'm trying to get the uid of the user like this:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
如果我尝试打印该uid,则一切正常,将打印uid.如果我尝试注销(在SecondActivity中)并再次登录,则会生成一个新的uid,这是正确的.问题是,如果我再次注销并卸载该应用程序并再次启动它,即使我等待5个小时,也会使用旧用户.
If I try to print this uid, everything works fine, the uid is printed. If I try to sign-out (in the SecondActivity) and sign-in again, a new uid is generated, which is correct. The problem is if I sign-out again and uninstall the app and launch it again, an old user is used, even if I wait for 5 hours.
如何解决此问题,因此,如果我注销,下一次使用我的应用程序使用上一个生成的用户而不是一个非常老的用户吗?
How can I solve this, so if I sign-out, next time I use my app to use the last generated user and not a very old one?
推荐答案
这是因为Android 6具有自动备份功能.如果您不希望备份数据,或者想要包含或排除某些资源,则需要在清单application>
标记中调整android:allowBackup
和android:fullBackupContent
.这不是错误.
It's because Android 6 has the automatic backup. You need to tune android:allowBackup
and android:fullBackupContent
in your manifest application>
tag if you don't want your data backed up or if you want to include or exclude some resources. It's not a bug.
您可以在此处
简而言之,为了避免这种行为,有必要将android:allowBackup="false"
和android:fullBackupContent="false"
放在manifest.xml中
In short to avoid this behaviour it is necessary to put android:allowBackup="false"
and android:fullBackupContent="false"
in manifest.xml
这篇关于注销匿名身份验证后,FirebaseUser不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!