There is no need to handle scenario 2 using a local database. Use Firebase.getDefaultConfig (). SetPersistenceEnabled (true) in the application class and create an android: name = "yourapplicationclass" in the manifest file. to handle synchronization when the network changes, i.e. an online / offline transaction handler to handle local synchronization with the firebase database, as some tome data does not fit on the firebase server. Similarly, I used the network replacement method and solved this problem:
mDatabase.runTransaction(new Transaction.Handler() { @Override public Transaction.Result doTransaction(MutableData mutableData) { if(mutableData.getValue() == null) { mutableData.setValue(1); } else { mutableData.setValue((Long) mutableData.getValue() + 1); } return Transaction.success(mutableData);
source share