1
I have a query in Firebase that should return the user data to check if he still has access and his level of access to the system, however when modifying the values the query continues bringing the previous values.
private void buscarUser(String matricula){
ValueEventListener buscaUserListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(!dataSnapshot.exists()){
Toast.makeText(BuscaUserPage.this,
"Usuário não encontrado.", Toast.LENGTH_LONG).show();
}else {
try {
Usuario userRecebido = null;
for (DataSnapshot dados : dataSnapshot.getChildren()) {
userRecebido = dados.getValue(Usuario.class);
idUser = dados.getKey();
}
atualizarTela(userRecebido);
}catch (Exception e){
Toast.makeText(BuscaUserPage.this,
e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(BuscaUserPage.this,
"Ocorreu um erro: " + Objects.requireNonNull(databaseError),
Toast.LENGTH_LONG).show();
}
};
Query consulta = referenciaFirebase.child("Usuarios").orderByChild("matricula").equalTo(matricula);
consulta.addListenerForSingleValueEvent(buscaUserListener);
}
User class:
public class Usuario implements Serializable {
private String id;
private String email;
private String senha;
private String matricula;
private int nivelAcesso;
private boolean ativo;
}
The level and active values that are changed.
You have activated Firebase’s Offline Persistence?
– Rosário Pereira Fernandes
Offline persistence is active.
– Ronaldo Nunes
That’s why you’re having this problem. It may be that it is taking too long to load the new values, or there may be a problem with your connection. This problem is common when using offline persistence.
– Rosário Pereira Fernandes