In this post you will find the different ways to implement offline capabilities when using
Firebase , information about when and why could be a good idea enable offline capabilities and examples of it with Android platform.
What should I use? Disk persistence or keepSynced calls?
From my experience I can say that it always depends of what your app is working, and how you manage the transactions and database of your application. If for example you have an application where the user is just writing and reading data but he is not able to delete or edit it, use
DiskPersistence would be the right choice.
DiskPersistence will store data in cache, which means that your app will use more space in the user's devices, which maybe is not the best idea in your case.
In other hand, if your application manages a lot of complex transactions and your data is updated really often, possibly you should avoid
DiskPersistence and use
keepSynced in the references that you want to keep fresh.
DiskPersistence stores the data retrieved in local, which sometimes can cause lot of desynchronization showing your data if you don't use it together with continous
ListenerValueEvents. For example:
To avoid this the best idea is keep continous listeners in the references that you want to track all time.
Can I use both together?
Of course you can, and in most of the apps possibly is the best idea to avoid download a lot of data and give the user the possibility to work with your app even if he has no connection.
If you don't care about use cache space in the user device, I recommend you to enable
diskPersistence in your
FirebaseDatabaseobject and also add a
keepSync flags to each reference that can have a lot of times in a short space time or you want to keep fresh all time.