0

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.

2
  • 2
    Retrieving data from the Firebase Database is done by attaching a listener. If neither your onDataChange() nor your onCancelled() is being called, it's most likely that your not connected to the network. Commented Jan 14, 2017 at 0:30
  • 1
    I don't know if you've already checked in other ways if onDataChange is called, but looking at the code above, I wouldn't rely on hitting the "DONE" Log. You're comparing Strings, you should use the .equals() method to compare Strings, not ==. stackoverflow.com/a/767379/5251523 Commented Jan 14, 2017 at 1:31

1 Answer 1

1

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"); } 
Sign up to request clarification or add additional context in comments.

1 Comment

Good catch! I overlooked that one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.