1

Starting to write an application using Android Studio, I ran into a problem regarding the firebase login command. The application is connected to firebase and the user list contains the provided strings for 'mail' and 'pw'. The method 'login()' should return one of both messages, but nothing is happening (not even an error message in the log). The code is given below:

public class MainActivity extends AppCompatActivity {

    FirebaseAuth firebaseAuth;
    Dialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FirebaseApp.initializeApp(this);
        firebaseAuth = FirebaseAuth.getInstance();
        if (firebaseAuth.getCurrentUser() == null) {
            logIn();
        }
    }

    private void logIn() {
        String mail = "example@gmail.com";
        String pw = "password";
        firebaseAuth.signInWithEmailAndPassword(mail, pw)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                       @Override
                       public void onComplete(@NonNull Task<AuthResult> task) {
                           if (task.isSuccessful()) {
                               Toast.makeText(getApplicationContext(), "Login successful", Toast.LENGTH_LONG).show();
                           } else {
                               Log.w("Sign in error: ", task.getException());
                               Toast.makeText(getApplicationContext(), "Login unsuccessful", Toast.LENGTH_LONG).show();
                           }
                       }
                   });    
    }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
BramH
  • 221
  • 5
  • 24
  • maybe define `mail` and `pw`? else an `OnCompleteListener` might never happen. – Martin Zeitler Aug 10 '18 at 19:02
  • I did that already, now also edited into the code above – BramH Aug 10 '18 at 19:03
  • and you are certain neither of them are `NULL`; maybe set a break-point? – Martin Zeitler Aug 10 '18 at 19:08
  • yes definitely, no break-point also – BramH Aug 10 '18 at 19:10
  • nope, you should set a break-point at `firebaseAuth.signInWithEmailAndPassword()` and inspect the values, step further into to the next break-point, eg. `onComplete()`. this answer states the installed `play-services` as a possible reason: – Martin Zeitler Aug 10 '18 at 19:12
  • Unfortunately that does not work, the Google Play services-version is 11.7.43 and I think it is up to date. – BramH Aug 10 '18 at 21:02
  • the current version is `12.8.74`, that's at least what I have installed. you might have to update device/emulator; build against Play Services Library & Firebase `15.0.0` + – Martin Zeitler Aug 10 '18 at 21:10
  • awesome! I was first trying updating but nothing worked. Now that I built a new emulator using the newest sdk-version, it is working. Thanks a lot! – BramH Aug 10 '18 at 21:19

0 Answers0