-1

I'm developing an Android app for salesman, so they can use their device to save their order. Specifically, every morning the salesman would go to the office and fetch the data for that day.

Currently, I can get the data by sending a request to php file, and like common practice we insert those data into sqlite in the Android so it can work offline. However, with current approach the device needs 6-8 seconds on getting the data and inserting those data to sqlite. As the data grow bigger I think it would make it slower. What I had found is that the process of inserting data into sqlite takes quite amount of time.

So, I've been thinking about dumping all data that is needed by the salesman into a sqlite file, so I could send only that file which I guess is more efficient. Can you please lead me on how to do that? Or is there any other way which is more efficient approach for this issue?

Note:

  • Server DB: Mysql
  • Server: PHP
Bla...
  • 7,228
  • 7
  • 27
  • 46
  • Send only those rows which are new? – Skynet Jul 15 '15 at 05:00
  • No, because every morning the salesman would go to the office and fetch the data for that day. it would be great if I could pick the tables and fields that I want to send to the device. – Bla... Jul 15 '15 at 05:02
  • If you want to make it totally automated, try Sync Adapters with Content Providers. That is what Gmail uses. As a downside to this you will have to use Account Manager as well. Without which the other two will not work. – Skynet Jul 15 '15 at 05:05
  • currently i am facing the same problem , if you try using bumping method, it will also take more time like web api sync – Sree Jul 15 '15 at 05:11
  • Thanks, but I think you got it wrong.. First of all, we assume that all device isn't 24/7 online and also I'm not asking on how I send the data from device to the server.. So, my problem is that when the salesman try to fetch the data, they need about 6-8 seconds loading time, only 2K rows, which I want to improve. I found that the inserting process to the `sqlite` takes quite amount of time. Is there any way to do so? – Bla... Jul 15 '15 at 05:13
  • 1
    Use transactions to insert data in SQLite, if you dont already. That is a bulk insert. – Skynet Jul 15 '15 at 05:15

2 Answers2

0

You can do here different approach to achieve loading speed:

  1. If your data can be pre-loaded with apk, you can just store those inside .apk and when user download app, it will be there, you just need to call remaining updated data.

  2. If you need refreshed data every time, you can do call chunk of data from server in multiple calls, which will fetch and store data in database and update on UI.

  3. If data is not too much, (I say, if there are 200-300 data, we should not consider it much more) you can do simple thing: When you call network call for fetching data, you should pass that data objects to database for storing and at same time (before storing in db), just return the entire list object to Activity/Fragment, so it will have the data and you can see those data to user, in mean time, it will store in database.

Also, you can use no-sql in side sqlite, so you don't need to parse objects every time (which is costly compare to no-sql) and store all data in sql as entire object and whenever require, just fetch from db and parse it as per requirement.

Kinnar Vasa
  • 397
  • 1
  • 9
0

Thanks to @Skynet for mentioning transaction, it does improve the process alot.. So I'll stay with this approach for now..

You can do something like so:

db.beginTransaction();
try {
    saveCustomer();
    db.setTransactionSuccessful();
} catch {
    //Error in between database transaction 
} finally {
    db.endTransaction();
}

For more explanation: Android Database Transaction..

Community
  • 1
  • 1
Bla...
  • 7,228
  • 7
  • 27
  • 46