1

In my app, I have two different activities, one storing data ("suggestions") to a Firebase database:

DatabaseReference suggestRef = FirebaseDatabase.getInstance().getReference().child("suggestion").child(someID).push().child("name");
suggestRef.setValue(suggestion);

and a second activity where a single of these suggestions is loaded and displayed for a moderator to accept or delete:

DatabaseReference suggestRef = FirebaseDatabase.getInstance().getReference().child("suggestion");
Query suggestQuery = suggestRef.limitToFirst(1);

suggestQuery.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

    //...

    }

Note that, when reading from the database, I'm accessing a parent location to where I write. This is because "someID" can be anything - and because more than one suggestion could be added for any value of "someID", I'm adding random child nodes via push() there. This is not the problem, I'm getting child nodes of the referenced node in the onDataChange() callback.

In any case, writing definitely works (checked via the web view of the database), as does accessing the node again - as long as I don't setPersistenceEnabled() for the database.

If I do, writing still works, but subsequently reading returns a null value at the referenced location.

Running the app again without persistence makes the data available - running with persistence later makes it unavailable again.

What am I doing wrong?

Andreas
  • 21
  • 2
  • Don't use both disk persistence and `addListenerForSingleValueEvent()` in a single app. They don't mix well. See http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent – Frank van Puffelen Mar 06 '17 at 14:38
  • Thanks Frank - that makes sense. – Andreas Mar 06 '17 at 16:09

0 Answers0