Huzi
Huzi

Reputation: 3

Firebase android problems

I'm using Firebase in android studio, and I want to make a signup and login project. I'm able to save data to the Firebase, but I can't retrieve data.

In every example, it's realtime --like, we set up a listener first and save data-- but mine is just storing and later retrieving.

Is there a way to just retrieve data? (I wish you could understand :( )

public void onLogIn(View v){
    reference2 = fbData.getReference(loginId.getText().toString());
    reference2.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String gotPw = dataSnapshot.getValue(String.class);
            if(gotPw == loginPw.getText().toString()){
                Log.d("TEST","DONE");
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d("TEST","ERROR");
        }
    });

}

This code doesn't even call the onDataChange method.

Upvotes: 0

Views: 272

Answers (1)

Aman Arora
Aman Arora

Reputation: 109

In java == operator to compare string doesn't always return true even if the string values might be the same.

Try doing:

if(gotPw.equals(loginPw.getText().toString())){
            Log.d("TEST","DONE");
        }

Upvotes: 1

Related Questions