Bog'liq Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019
Wri/ng data when offline Disconnect your mobile device from the network and run your app. Add a new post.
You'll see that the post appears on the home screen like it was added to the database.
But how is that possible if you are offline?
Open the Firebase console and check if your post is there. You'll notice that it's not.
Now, connect your mobile phone to the network and observe the database data in
the console. You'll see that a few moments after you connect your app back to the
internet your post appears in the database.
Setting the
setPersistenceEnabled
method argument to
true
also keeps track of
all the writes you initiated while you were offline and then, when network
connection comes back, it resends all the write operations. This makes the user
experience optimal even if the user loses the network connection for a moment,
because your app works as if it's connected to the internet because it uses local data
from the disk for synchronization.