Reputation: 335
I am not sure if that is what firebase is supposed to do, but when I use this line:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Everything is great I can use the app offline. But what I am hoping to achieve is that, when a user adds something in offline and closes the app. And when the network connection restores user doesn't have to open the app again, it should sync itself without opening the app. Is it possible?
Upvotes: 0
Views: 88
Reputation: 317372
Enabling persistence won't force a sync any time there is a network connection. Your app has to be running and in the foreground in order for the SDK to reconnect to Realtime Database and synchronize any pending writes. There is nothing in the SDK that will wake your app when it's not running in order to perform the sync. If you want, you can arrange for that yourself, but that is beyond the scope of this question.
Upvotes: 1
Reputation: 1
You can enable disk persistence with just one line of code.
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Upvotes: 0