Recommended way / order to read data from a webservice, parse that data and insert it in a SQLite db

I decided to come to you because you’re the experts

first i am not expert and also i am not knowledgeable you can find more expert people than me but this is my opinion hope to give you some help.

first of all forget to use AsyncTask to download because it must be used for short background jobs not like yours i think the amount of file you want to download is pretty large.(i think so)

check downloadmanager of google to see how it works it may help you.

http://developer.android.com/reference/android/app/DownloadManager.html

http://blog.vogella.com/2011/06/14/android-downloadmanager-example/

if you want to use service use unbound service because you do not want the service to be destroyed by android or user when the user close the apps do you? i think you want to get your data any way.

in order to be efficient i recommend these steps:

a. Read a restful service to retrieve the Customers Data

b. when you get Customer data do :

  • create another service or thread to Read a restful service to retrieve the Articles Data

  • Parse the response to Json Objects on your old service or thread

now you have 2 services or threads that run concurrently so follow the steps that obvious insert parse and so, on each service or thread.

why do not i combine a and d? because i think user do not like to wait much time behind download progress bar.

in order to insert your data to database use transaction and i recommend you use:

http://greendao-orm.com/

it is more efficient ORM than others for database and you get free from db implementation.

If the activity that started the service is explicitly cancelled or is hidden by another activity, the service has to have a way to let the user know that the process has finished. How could I implement that?

use notification:

http://developer.android.com/training/notify-user/build-notification.html

http://www.tutorialspoint.com/android/android_notifications.htm

http://www.vogella.com/tutorials/AndroidNotifications/article.html

While all this long processing is taking place in the background I’ll have to show some sort of indicator (a ProgressDialog) This is the reason I opted for using a Bound Service`

how can I update the UI from an Unbound Service?`

Use a LocalBroadCastManager, or in general BroadCastReciever

Android update activity UI from service

In J2ME I’ve done something similar, and when I put something like the 6 steps I mentioned above all of them are executed sequentially, that is , one after the other. Is it the same in Android?

this is depends on your steps, if you follow my idea you run concurrently and if you run your idea you will run sequentially.

Good Luck.

Leave a Comment