Java – Google Firebase Authentication Android Studio

Google Firebase Authentication Android Studio… here is a solution to the problem.

Google Firebase Authentication Android Studio

I’m trying to configure a new Google Firebase authentication in my app.

When running the following command in the button’s OnClickListener, I get canresolve 'addOnCOmpleteListener'.

If I move the firebase call out of the button onClickListener, I get an error

I don’t quite understand why the method can’t be accessed from the button call

Any help would be appreciated

package com.example.alex.test;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class LoginActivity extends AppCompatActivity {
    private FirebaseAuth mAuth;

private FirebaseAuth.AuthStateListener mAuthListener;

Button buttonLogin;
    EditText textEmail;
    EditText textPassword;

    protected void onCreate(Bundle savedInstanceState) {

mAuth = FirebaseAuth.getInstance();

buttonLogin = (Button) findViewById(;
        textEmail = (EditText) findViewById(;
        textPassword = (EditText) findViewById(;

mAuthListener = new FirebaseAuth.AuthStateListener() {
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                     User is signed in
                    Log.d("LOG_Login", "onAuthStateChanged:signed_in:" + user.getUid());
                } else {
                     User is signed out
                    Log.d("LOG_Login", "onAuthStateChanged:signed_out");
                // ...

buttonLogin.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                 Perform action on clic

                        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                Log.d("LOG_Login", "signInWithEmail: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()) {
                                    Log.w("LOG_Login", "signInWithEmail", task.getException());
                                    Toast.makeText(getApplicationContext(), "Authentication failed.", Toast.LENGTH_SHORT).show();

// ...


I’m using Android Studio 2.2

I created a project in Firebase

I have connected my application to this in the GUI


If i move the firebase call out of the buttons onClickListener then the error goes,

I cant quite understand why the method is not accessible from within the button call

Because this is a click listener in the anonymous class.

This method requires an activity as the first parameter of addOnCompleteListener, not OnClickListener.

.addOnCompleteListener(LoginActivity.this, ... 

Related Problems and Solutions