I’m working on Android project where I’m collecting some information from web server. Everytime the application starts I’m downloading JSON data and reenter the information in database. I have this scenario :
- Application starts, I’m deleting all data in sqlite database and
insert it again (that’s needed if there are some changes in json
data). - While I’m downloading the new json user can’t see any information because I’ve already delete it. He can see periodically when the single items are downloaded and insert in database.
- After whole process is done and everything is downloaded and insert user can see all the new available information.
So I need an idea how to do this thing: When I start downloading the data from json when app starts user must be available to see the old info. When I’m ready with all the information and everything is downloaded, the whole JSON I have to delete/update/insert the new data and everything must happen so quick that the user must don’t notice that.
Any idea how can I do this?
Thanks in advance!
There are 3 possibilities.
AsyncTask
This is the first ‘obvious’ choice until you realize the framework has many issues with it (like how to handle onConfigChange)
ContentHandler / Account / SycnService
This is the most complicated solution. First you must know these 3 pieces come together. So you’ll have to write a “dumb” Account if you don’t need one, and a “half-dumb” ContentHandler if you have a SQLLite.
Service
I chose to use an IntentService and I am very satisfied.
my.app.DATA_UPDATED. And send an Intentmy.app.DATA_REQUESTEDIntentServiceis declared in the manifest with intent filter DATA_REQUESTED.