3

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,

2
  • 1
    use local database Commented Apr 26, 2018 at 7:50
  • As said by @YogeshPaliyal you NEED a local database on your driver's phone, that's mandatory to do this.
    – N.K
    Commented Apr 26, 2018 at 7:59

5 Answers 5

10

You can follow these steps in your app:

  1. Create a Local Database with a schema that holds the information regarding the stops and items.
  2. In the beginning, when a driver is starting his journey, he must be having the Internet. Fetch all the deliveries information and save it to the local database for use.
  3. Show this list to the driver from your local database.
  4. You can have 2 Flags named delivery_status and synced. Initially, delivery_status can be in_transit and the synced flag must be false.
  5. Create a background service that keeps checking for Internet Connection at a certain interval. If there is no internet, the service stops and nothing happens. But, if there is an Internet, fetch all the unsynced **(synced = false) ** data from the local database, and send the data to the server. After a successful response from the server, mark this synced flag to true. Repeat this step at every certain interval to check for unsynced data and keep sending this to the web server until all synced flags are true.

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.

3

Save the order(s) status first in a SQLite database. Then once an internet connection is attained, try to sync all the data.

1

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.

1

You can also use Couch base db. sync data to the server through sync gate way

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.