-1
    database = FirebaseDatabase.getInstance();
     myRef = database.getReference("Update");

    // Read from the database
    myRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // This method is called once with the initial value and again
            // whenever data at this location is updated.
            String value = dataSnapshot.getValue(String.class);

            if (value.toString() == "1.0")
            {
                Toast.makeText(getApplication(), "No Update" , Toast.LENGTH_LONG).show();
            }
            else {Toast.makeText(getApplication(), "Need Update" , Toast.LENGTH_LONG).show();}

        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Toast.makeText(getApplication(), "Failed to read value." + error.toException() , Toast.LENGTH_LONG).show();
        }
    });

value is 1.0 and string in if is 1.0 but when i run the app show me need update, why is that? i want hem to show me update.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
sosan
  • 13
  • 6

1 Answers1

0

You are comparing string with == operator. It will return true if and only if both reference point to the same object.

Use String.equals to compare strings.

Puneet
  • 653
  • 1
  • 7
  • 18