0

How do I pass/get a task.getexeption as a string to a custom dialog? I am attempting to pass the !task.isSuccessfull() exception to the authFailDialog instead of using toast and not sure how to do it (It's been 5yrs since Iv'e worked with Android/Java ;)

Pass from:

auth.createUserWithEmailAndPassword(email, password)
        .addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>()
        {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                progressBar.setVisibility(View.GONE);
                // If sign in fails, display a message to the user. If sign in succeeds
                // the auth state listener will be notified and logic to handle the
                // signed in user can be handled in the listener.
                if (!task.isSuccessful())
                {
                    //Toast.makeText(SignupActivity.this,"Authentication failed." + task.getException(),
                      //Toast.LENGTH_SHORT).show();
                    authFailDialog.show();
                }
                else
                {
                    agreementDialog.show();
                }

            }
        });

To this:

final MaterialStyledDialog.Builder authFailDialog = new MaterialStyledDialog.Builder(context)
        .setHeaderDrawable(R.drawable.cityview)
        .withDialogAnimation(true)
        .setTitle("Oh Snap!")
// This is where I need the exception - `task.` is un-resolvable
        .setDescription("Authentication failed." + task.getException()
        .setPositiveText("Send Feed Back")
        .onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                //TODO: Create feedback form.
                }
            })
        .setNegativeText("Try Again");

1 Answers1

0

I just moved it into the task. e.g.:

auth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>()
    {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            progressBar.setVisibility(View.GONE);
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful())
            {
                new MaterialStyledDialog.Builder(context)
                .setHeaderDrawable(R.drawable.oh_snap)
                .withDialogAnimation(true)
                .setTitle("Oh Snap!")
                .setDescription("Authentication failed. " + task.getexception())
                .setPositiveText("Try Again")
                .onPositive(new MaterialDialog.SingleButtonCallback()
                    {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which)
                        {
                            //TODO: Clear text fields.
                        }
                    })
                    .show();
            }