首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Firebase Realtime删除帐户

使用Firebase Realtime删除帐户
EN

Stack Overflow用户
提问于 2020-01-20 09:56:12
回答 1查看 45关注 0票数 1

我在删除用户帐户时遇到问题。删除代码成功,并且工作正常。唯一不起作用的是删除帐户后,应用程序应该将用户带到登录页面,但它会将用户带到mainActivity页面,这很奇怪,为什么它会这样呢?我不知道哪里出了问题。

代码语言:javascript
复制
//update account

 if (currentUser != null) {
            userId = currentUser.getUid();
            databaseReference = FirebaseDatabase.getInstance().getReference("Customer").child(firebaseAuth.getUid());


            databaseReference.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    Customer cust = dataSnapshot.getValue(Customer.class);
                    name.setText(cust.name);
                    address.setText(cust.home_address);
                    phone.setText(cust.telephone_number);
                    email.setText(cust.email);

                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });

            update.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                            Log.i("Test", name.getText().toString());
                            dataSnapshot.getRef().child("name").setValue(name.getText().toString());
                            dataSnapshot.getRef().child("home_address").setValue(address.getText().toString());
                            dataSnapshot.getRef().child("telephone_number").setValue(phone.getText().toString());

                            Toast.makeText(getApplicationContext(), "Successfully updated!", Toast.LENGTH_LONG).show();
                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {
                            Log.d("User", databaseError.getMessage());
                        }
                    });
                }
            });

        }



public void deleteAccount(View view) {
        progBar = findViewById(R.id.progBar);
        firebaseAuth = FirebaseAuth.getInstance();
        AlertDialog.Builder dialog = new AlertDialog.Builder(CustProfileActivity.this);
        dialog.setTitle("Are you sure ? ");
        dialog.setMessage("Deleting this account will result in completely removing your " +
                " account from the system and you won't be able to access the app.");
        dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                progBar.setVisibility(View.VISIBLE);
                FirebaseDatabase.getInstance().getReference().child("Customer").child(firebaseAuth.getCurrentUser().getUid()).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            progBar.setVisibility(View.GONE);
                            Toast.makeText(getApplicationContext(), "Account Deleted", Toast.LENGTH_SHORT).show();
                            FirebaseAuth.getInstance().signOut();
                            Intent intent = new Intent(CustProfileActivity.this, LoginActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                            finish();
                        } else {
                            Toast.makeText(CustProfileActivity.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
                        }

                    }

                });
            }
        });

        dialog.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();
            }
        });

        AlertDialog alertDialog = dialog.create();
        alertDialog.show();

    }

EN

回答 1

Stack Overflow用户

发布于 2020-01-20 10:38:44

你能用下面的代码替换这一行吗:

代码语言:javascript
复制
 if (task.isSuccessful()) {
                        progBar.setVisibility(View.GONE);
                        Toast.makeText(getApplicationContext(), "Account Deleted", Toast.LENGTH_SHORT).show();
                        FirebaseAuth.getInstance().signOut();
                        Intent intent = new Intent(CustProfileActivity.this, LoginActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        finish();
                    }

有了这个:

代码语言:javascript
复制
  if (task.isSuccessful()) {

                    progBar.setVisibility(View.GONE);
                    Toast.makeText(getApplicationContext(), "Account Deleted", Toast.LENGTH_SHORT).show();
                    FirebaseAuth.getInstance().signOut();
                    Intent intent = new Intent(CustProfileActivity.this, LoginActivity.class)
                    startActivity(intent)
                         finishAffinity()

                    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59816108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档