Keep data from the Firebase Realtime Database always in sync

后端 未结 2 485
野的像风
野的像风 2020-12-20 01:00

I\'m currently re-working an app of mine which updates it\'s internal SQLite database by fetching raw data from an website, not an official API.

As this is quite err

相关标签:
2条回答
  • 2020-12-20 01:25

    Your first approach is trying to ensure the Android app always has an open connection to the Firebase Database backend. This has been asked/tried before(see here, here), and is definitely possible. But you'll be fighting with Android updates, which are specifically trying to reduce battery usage by this type of behavior in apps.

    The second approach is indeed better. I often refer to it as "push to sync", since you're sending a push notification (through FCM) to trigger a data sync. (plus: it's a word play on the "pull to sync" pattern so many apps follow). An example of an app using this approach is Google's I/O app for Android from 2016, the code for which is on Github. The code is a bit convoluted, but the actual sync is here and (iirc) it is triggered through this.

    0 讨论(0)
  • 2020-12-20 01:30

    FCM would be a great choice for you considering that using only push data without notification as this forces the sent to data to be received in the onReceive method in your mobile application. If your device is offline it will resend the data again while it comes online again.

    Whenever any change happens in your backend send push data to your devices using their presaved tokens.

    0 讨论(0)
提交回复
热议问题