I am developing an Android app that stores data locally in Sqlite database and sync it to a remote server (MSSQL server). The sending of data is handled through REST api.
This is the way I would like it to work and my plan to handle it:
When the app stores data in Sqlite database, the app will check if internet connection is available, if it is then the app will make a HttpPost to send the data (I use AsyncTask to handle this). Once the data sent, I will flag the row in the database as "synched" using postExecute callback.
If the internet connection is not available, then the app will continue on.
I need to make the app to listen to the event when internet connection became available and then the app will go through all rows that have not been synched and use AsyncTask again to send the data to remote server.
My questions are:
Thanks,
The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.
Offline sync allows end users to interact with a mobile app—viewing, adding, or modifying data—even when there's no network connection. Changes are stored in a local database. Once the device is back online, these changes are synced with the remote backend.
The Sync apps are available for Android, iPhone and iPad, and make it easy for you to access your files right from your mobile device. The Sync apps are free, and provide the following features: Access your files in Sync from anywhere. Use third-party apps on your device to open and edit files in Sync.
You could implement this manually, but I suggest you use a SyncAdapter instead.
Although you can design your own system for doing data transfers in your app, you should consider using Android's sync adapter framework. This framework helps manage and automate data transfers, and coordinates synchronization operations across different apps. When you use this framework, you can take advantage of several features that aren't available to data transfer schemes you design yourself.
If you want to implement this without using a SyncAdapter
anyway, then for the "detect when connection becomes available", you need to add a BroadcastListener
to listen for CONNECTIVITY_ACTION
broadcasts, then use a ConnectivityManager
to query about the current state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With