Downloading screen in a Mobile application is into the buzzwords. Sometimes an application requires large amount of data to be downloaded before going to be ready for use. On application launch, we call all the web-services and get data from server end and further we insert it to our local sqlite database. The whole process takes a lot of time to get completed. However, we can optimize the load time of data and can insert it further into database of particular platform.
For example, if we are getting data from 10 web services to setup our application to use. We have three ways to perform it handsomely:
Calling all web services on the same time and inserting data into database:
The response time of all web-services is conditional and only after getting response we can insert data into database. If more than one parser finished parsing and inserts data into database at the same time, database will show an error “database is locked”. However, we can perform a single query on our sqlite database because every single query locks the database and opens it after completing it.
Calling web services One by One and Inserting data into database:
In this situation the parsing will take more time because every parser will wait until the previous parser finishing its process. A parser will download the data from server and then parse it. After parsing, it will insert the data into database. So the downloading screen will take more time but this approach will not give “database is locked” error.
Calling all web services on same time and Inserting data into database in a queue:
In this situation we are calling all the web services on same time. All the parsers will finish downloading and parsing on different or sametime. After finishing parsing, every parser will insert data into database with the help of a queue maintained. This approach will decrease the parsing time and further insert data into database in a queue. So, it will never give the error “database is locked”.
We have discussed three ways to parse data from web-service and its insertion into local database. The third way is the best way to download and insert data into database because we call all the parsers on the sametime and further inserting data into database. In this situation the database insertion may take bit more time if the data to be inserted is in mass. For example, if we are using 50,000 records for an entity then we have to insert it into database and the number of record will take the time around 8-9 minutes. With Sqlite you can only insert 100 records in a second.
Inserting number of records into database:
When we insert number of records into database we run a loop to insert the data into database. In our case it will insert 50,000 rows in a table one by one. To insert all the data in one short we will use the “TRANSACTION BEGIN” and “TRANSACTION END” that will reduce all the time of insertion data into database and data will be inserted within 5-10 seconds.
In a nutshell, these processes are really worthy to keep your web service and insertion of data in fastest manner. This is something experieced by me few days ago and hope it will help you the same to make the entire process happen in realtime.