1

I'm getting list of data from firebase database by following method

//firebase reference
DatabaseReference ref = FirebaseDatabase.getInstance().getReference()
                       .child("someNode);

//ref.keepsynced(true);

//Query 
Query query = ref.orderByChild("createdAt").limitToLast(10);

//listener
final ValueEventListener listener = new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              //dataSnapshot is null 
             //when I delete the list from the client 
            //and try to login again with some data in firebase database
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        };

// Add listener
query.addListenerForSingleValueEvent(listener);

Whenever I delete the list of data from the client and try to logout and login again with some data in the firebase database under "someNode", I'm getting the value from the firebase cache (i.e null in my case). When I setPersistenceEnabled to false, the datasnapshot returns the data from the firebase. It will be helpful to know that I'm doing anything wrong or is there any method to solve this issue? Thank you.

Samuvel P
  • 11
  • 2
  • Using `addListenerForSingleValueEvent` doesn't combine well with disk persistence. See https://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent for an explanation of the flow, and the solution (using `addValueEventListener`). – Frank van Puffelen Sep 22 '18 at 13:34

0 Answers0