0

I am creating an application using Google Firebase, and I used some of the code they provide for you to use, but I don't know what a few of these variables are. the variables are "auth_failed" and "EmailPasswordActivity".

 mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>()
    {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task)
                {
                    Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                    // 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(EmailPasswordActivity.this, R.string.auth_failed, Toast.LENGTH_SHORT).show();
                    }
                }
    });

1 Answers1

0

I recommend you have a look at the [documentation for Toast.makeText()](https://developer.android.com/reference/android/widget/Toast.html#makeText(android.content.Context, int, int)), since these variables are passed into the first and second arguments of that method.

The first argument is documented as:

Context: The context to use. Usually your Application or Activity object.

So in this case it EmailPasswordActivity.this refers to the activity that the code is in. See What is different between MainActivity.this vs getApplicationContext() for the .this suffix in this context.

The second argument is documented as:

resId int: The resource id of the string resource to use. Can be formatted text.

So this is a string resource (in your app's strings.xml file) that contains the text to display.

By the way: the code snippet in the documentation links to the complete example on Github.

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I'm very confused as to what a context is or how to use/create one. – Alexander Hargraves Apr 05 '17 at 19:34
  • It's used by Android to constrain the life-cycle of (in this case) the Toast. It's not Firebase specific, so I'd read some more about it in the Android docs to get unconfused and/or http://stackoverflow.com/questions/3572463/what-is-context-on-android. – Frank van Puffelen Apr 05 '17 at 21:50