Reputation: 89
I am working on android application which is driver application. The main of the driver application is to deliver the orders for the a particular client.
The driver will received a bulk of orders and he can change the status of each one e.g. (in_transit, on hold, delivered, canceled, rejected). Once the internet connection is dropped the driver is blocked from any action.
My goal is how can i make the application running in offline mode, once the internet connection is dropped the driver is still can take an action of each order and he can change the status locally for each one from new to in_transit to deliver and so one. And once the internet connection is back i can sync/push the data to server.
So my questions are: - How can i do that? - What should i saved to sync the api requests or order status?
Thanks,
Upvotes: 3
Views: 11158
Reputation: 1219
First fetch all orders from server and saved to local database for local database use SQLite
Driver update the status locally i.e in SQLite local database.
Use an background service to check internet connection is available for each 15 min.
Make one status table in local db , If internet connection is available, send data to server and change status in local created table as a true by default it is false
Next time send only data has status false in local db.
Upvotes: 0
Reputation: 2877
You can follow these steps in your app:
This way, you can make the driver deliver the items without having internet at times, and as soon as the internet is available, your background service will upload the status to the server.
Upvotes: 10
Reputation: 3275
You can also use Couch base db. sync data to the server through sync gate way
Upvotes: 1
Reputation: 7367
The issue is that you need to save the data locally so that it can persist until you get the chance to send it to the server.
Your first decision is what behavior you want if the app is closed.
If you want it do be saved even if the user closes the app, then you will need to write that data to disk. You can do that by writing to file (with a json), saving the data in SharedPreferences
(if you only have a small amount of data), or by using a database. Databases are the most common approach if you will have a lot of data.
As far as databases go, Android natively supports SQL lite, but that may be difficult for a beginner. I would suggest looking into Realm, which I find very intuitive to use.
If you don't mind the data being forgotten if the user closes the app, then you could just put the data into one of the numerous Java collections, like an ArrayList
, LinkedList
, or Stack
until the connection is restored. However, like I said, you run the risk of losing this data if the app is closed before the data is sent.
Upvotes: 1
Reputation: 237
Save the order(s) status first in a SQLite database. Then once an internet connection is attained, try to sync all the data.
Upvotes: 3