2

I want to create a POS application but for some reason the application should be working when there is no internet connection (and later do the synchronisation when connect to internet). the only method that came to my mind is synchronising between local db with server but I dont have idea how to or the best method to do this. I have several question about this:

  1. is it possible to use FCM cloud messaging to do this ? I mean Client A tell FCM data has changed, and then FCM tell several clients (phone) to do sync db in the background without user's (phone owner) confirmation (automatically).

  2. or the only way is to use this method https://github.com/codepath/android_guides/wiki/Server-Synchronization-(SyncAdapter) ? if it's so, how often we can synch db local with server? is synchronising each 3 minutes will be fine?

Kakashi
  • 3,329
  • 4
  • 26
  • 37
  • Sync every 3 min will not be fine, that will be too often. You can use PushNotification (Point 1) and for backup point 2 as well. Point 2 will help when the device is switched off or no internet connectivity. – Saran Sankaran Dec 18 '17 at 13:25
  • FCM messages will not be sent/received when there is no internet connection on the device – kenny_k Dec 18 '17 at 13:40
  • 1
    Possible duplicate of [Sync data between Android App and webserver](https://stackoverflow.com/questions/10829371/sync-data-between-android-app-and-webserver) – kenny_k Dec 18 '17 at 13:41
  • i meant we can tell FCM data has changed when there is connection, right? – Kakashi Dec 18 '17 at 13:44

1 Answers1

2

Yes, use FCM real-time database for this. FCM manages data for you internally on the app, as well as on the cloud. So if you write some data into your JSON tree but you don't have internet connection, the data will be pushed into the cloud once the connection is available. The documents clearly state this (Read last section on 'Writing Offline Data': https://firebase.google.com/docs/database/android/read-and-write

Also, any data added to the database when your client was offline will be sent once the client goes online - because the real-time database keeps storage of the data as well.

Using a server-sync every 3 minutes is not feasible - and it is more likely that your app will get killed by the system at some point or the other. Use FCM and Cloud Functions along with JobSchedulers to get the best result.

user3324792
  • 109
  • 1
  • 2
  • 9