I am setting offline persistence
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
as described in an earlier post, but the following use case fails:
- Turn internet connectivity OFF on handset
- Attempt writing to the DB
- Kill app from the memory using the users' multitasking menu in the OS
- Turn internet connectivity back ON
- Relaunch the app. At this point I expect the new record from step 2 to be sent to the DB via the restored network connectivity, but this does not happen. (Are my expectations correct?)
Sample code:
static{
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
void updateValue(){
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("mydb");
dbRef.keepSynced(true);
dbRef.setValue("123");
}
Note that, if I don't kill the app from memory the caching works:
- Turn internet connectivity OFF on handset
- Attempt writing to the DB
- Turn internet connectivity back ON
- The new record is sent to the DB once the network connectivity is restored.
setValue()
it indeed should have been persisted to disk.FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG)
. The logcat messages are very detailed. You might find that output helpful.