Reputation: 61
I have app which during launch create anonymous user ID, but after uninstall my app create new user with new ID. How can I get userID which was before uninstall ?
My code to anonymous login:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mAuth = FirebaseAuth.getInstance();
if(mAuth.getCurrentUser() == null){
createUser();
}else{
user = mAuth.getCurrentUser();
}
}
public void createUser() {
mAuth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Log.d("TAG", "signIn: succes");
}else{
Log.w("TAG", "signIn: fail");
}
}
});
}
Upvotes: 0
Views: 881
Reputation: 138999
You can use Firebase Authentication to create and use only temporary anonymous accounts to authenticate with Firebase. Anonymous authentication
accounts don't persist across application uninstalls. When an application is uninstalled, everything that was saved locally will be deleted, including the anonymous auth token that identifies that account. Unfortunatelly, there is no easy way to reclaim that token for the user.
Instead, you should encourage all your users to fully log in with a supported account provider (Google
, Fabcebook
, Twitter
and so on) so that they can log in from all their devices without worry of losing their data.
Upvotes: 1