mardi 30 juin 2015

How do you synchronize data between SQLite and Azure in Android?

Ladies and Gentlemen,

I am currently working on an Android app, which is connected to a Microsoft Azure Backend. I have some trouble, synchronizing the app's database with the backend, as my current approach seems overly complicated. I searched for best practices / tutorials on synchronization without using SyncAdapter, but could not find anything that covers both storage and synchronization.

Functionality: A user can subscribe to a topic. This subscription shall be pushed to the Backend, so that the backend can send push notifications. So, the backend has to know, which users subscribed to which topics.

Task: Subscriptions are created and deleted on the Android app via a button click. They have to be stored offline in a database and also synced with Azure.

Current Approach: After reading multiple tutorials on databases and synchronization with android, I chose the following approach:

  • Subscriptions are directly saved in a SQLite database on the phone. Each subscription is saved with lastUpdated = now() and deleted = false. If a subscription is deleted, lastUpdated is updated and deleted is set to true.
  • A DataSynchronizer listens to updates and deletes on the subscription table. He stores the time of the last sync, lastSynced. For every update / insert / delete, he collects all subscriptions with lastUpdated > lastSynced and applies the changes via the MobileServiceClient provided by Microsoft Azure.

My question: Is there something you would do differently? As I said, this solution seems complicated and not like the best practice way.

Aucun commentaire:

Enregistrer un commentaire