After uninstall app creating new user insted of get userID from Firebase

北慕城南 提交于 2019-12-04 05:51:54

问题


I have app which during lunch create anonymous user ID, but after UN-install my app create new user with new ID. How can I get userID which was before UN-install ?

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");
                }
            }
        });

    }

回答1:


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.




回答2:


Store id in SharedPreferences before app uninstall.



来源:https://stackoverflow.com/questions/47136603/after-uninstall-app-creating-new-user-insted-of-get-userid-from-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!