delete()有时不起作用

时间:2017-04-03 05:54:09

标签: android firebase firebase-realtime-database firebase-authentication

我在我的应用中设置了帐户停用活动,但user.delete()方法有时无效...

它有时会起作用并且在其他时间不起作用的事实真的令人困惑......如果它是一个逻辑错误它不应该一直都能正常工作吗?

这是我的代码

deactivateAccount.setOnClickListener(new View.OnClickListener() {
    final FirebaseUser user = mAuth.getCurrentUser();

    @Override
    public void onClick(View view) {
        deletePosts();
        deleteComments();
        deleteLikes();
        deleteUser();
        user.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {

                Toast.makeText(DeactivateAccount.this, "You account has been deactivated",Toast.LENGTH_LONG).show();
                Intent loginIntent = new Intent (DeactivateAccount.this, LoginActivity.class);
                startActivity(loginIntent);

            }

        });


    }

没有错误,所以我也不知道如何调试它...但是deletePosts(),deleteComments(),deleteLikes()和deleteUser()方法都可以完美地工作......但是它使用户在身份验证选项卡中未删除...他们的电子邮件仍在那里。

非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试设置您的意图并在

中调用startActivity()
FirebaseAuth.AuthStateListener() onAuthSChanged()

方法。

    // This listener will be called when there is change in FireBase user session
    FirebaseAuth.AuthStateListener authListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user == null) {
                // user auth state is changed - user is null
                // launch login activity
                startActivity(new Intent(DeactivateAccount.this, LoginActivity.class));
                finish();
            }
        }
    };