Keep data from the Firebase Realtime Database always in sync

后端 未结 2 497
野的像风
野的像风 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.

提交回复
热议问题