Real-time data synchronization – Kiruthika P

Offline Sync in Mobile Applications – Kiruthika P
April 17, 2018
New Time Field Reference in Odoo – Athiban Raj T
April 18, 2018

Real-time data synchronization – Kiruthika P

I wrote about offline sync in mobile apps and how to make it work in my previous article. This time, I have something even better’Real-Time Sync’. This is a more advanced alternative to offline sync because it’s an automatic process. I’m sure this is going to come in handy at some point of time, so read on to know how it works.

What is Real-Time Synchronisation?

The primary purpose of Real-Time Sync is to execute a set of coding each time a change is detected in one of the monitored data. Here, the offline data (which is stored in the local database) gets synced to the server when it’s connected to the network.

Why we need Real-time Sync?

Nowadays all mobile app developers are trying to build an app that’s automated to the best possible extent so I believe it is essential that data is synched to the server automatically rather than going through a ‘click and click’ process.

The advantages are:

  • It frees up your app data storage space
  • It improves the performance of your app
  • It makes your app smarter and more user-friendly
  • It reduces data loss

Here’s how it works:

This is just a continuation of the offline-sync so I hope you remember how that worked. Consider that we have offline data in our local database. The data would get synched on the click of a button. Here we are going to sync data without any clicks which means no manual action will be required to sync the data.

To bring this option, we need to have some service running in the background which will check the network change often. Now you’re wondering what service and how it works.

A service is a component that runs in the background to perform long-running operations without needing to interact with the user and it works even if the application is destroyed. Service has life cycle callback methods that you can implement to monitor changes in the service's state. For example, a service has many callback methods like onCreate(), onBind(), onDestroy(), etc.

You can perform the tasks using these methods. To create a service, create a Java class that extends the service base class or one of its existing subclasses. The service base class defines various callback methods.

By calling those service methods, we can check the network changes and sync the data with the server. If you’re still not entirely clear about the working of a service, take a look at this link https://developer.android.com/training/run-background-service/create-service.html

On to the next question: Why do we need these services? If a device is connected to the network, you have to send the data to the server automatically. At this point, you have to run a code in background. Now create a service and add the code for the server to call for datasync. So once the device is connected to a network, the service will send data to the server and then clear the data from your local storage. This way, you can make use of the additional space that just got cleared up. Just like the offline sync, your data will be stored in the local database when you’re offline, but the difference is that the data will automatically get synched to the server when you are online again.

I wrote about offline sync in mobile apps and how to make it work in my previous article. This time, I have something even better’Real-Time Sync’. This is a more advanced alternative to offline sync because it’s an automatic process. I’m sure this is going to come in handy at some point of time, so read on to know how it works.

Leave a Reply

Your email address will not be published. Required fields are marked *