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();
}
});
值为1.0,如果为1.0,则字符串在运行应用程序时显示需要更新,为什么会这样?我想要下摆给我看看更新。
答案 0 :(得分:0)
您正在将字符串与==
运算符进行比较。当且仅当两个引用都指向同一个对象时,它才会返回true。
使用String.equals
来比较字符串。