Delete firebase user

Asked

Viewed 56 times

-2

Good afternoon, I’m having trouble settling an issue. I’m inside a fragment programming my delete account button, but it’s not working, nothing happens when I click on it, I think there’s something smashed.If anyone can help me thank me.

buttonExcluirConta.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle("Certeza?");
        dialog.setMessage("Deletar");

        dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

                firebaseUser.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {

                        if(task.isSuccessful()){
                            Toast.makeText(getContext(), "Conta  Excluida", Toast.LENGTH_LONG).show();

                            Intent intent = new Intent(getContext(), Login.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        }else{
                            Toast.makeText(getContext(),task.getException().getMessage(), Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        });



       // removeConta();


    }
});

In this case this code is inside a Fragment.java It is correct that I present you this way getActivity as low?

new Alertdialog.Builder(getActivity());

I put the dialog.();

Only the dialog went red...

1 answer

0

You are creating and configuring a dialog at the push of the button. However, you need to enter the command to effectively show the dialogue. So nothing happens, the dialog is created and configured but is not shown.

The method that should be called to show a dialog is: dialog show.();

So the right thing would be:

buttonExcluirConta.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle("Certeza?");
        dialog.setMessage("Deletar");

        dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

                firebaseUser.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {

                        if(task.isSuccessful()){
                            Toast.makeText(getContext(), "Conta  Excluida", Toast.LENGTH_LONG).show();

                            Intent intent = new Intent(getContext(), Login.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        }else{
                            Toast.makeText(getContext(),task.getException().getMessage(), Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        });



       // removeConta();

    dialog.show();
    }
    //MOSTRAR O DIÁLOGO
    
});
  • The.show() dialog command must be directly below the dialog command.Setpositivebutton ... If it was marked in red it is because it was outside the scope of the Onclick method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.