1

Is there a way I can store the value retrieved from the Firebase to be stored in a String Variable? Here is my code retrieving the Value of "rface":

ref.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
                @Override
                public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
                    rface = dataSnapshot.child("face").getValue(String.class);
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });

And I want to implement and if condition:

if (rface=="0") {
    do this
}

The rface contains a string value in my Firebase Database.
When I try to use this If condition Android Studio says:

Operator "==" can not be applied to 'java.util.Objects','java.lang.String'

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sagar Duhan
  • 257
  • 3
  • 15

1 Answers1

1

You should cast your object to a String like this:

rface = (String)dataSnapshot.child("face").getValue();

and then compare with equals();

T.S
  • 911
  • 8
  • 24