ok this is my first post,
i have a ListView that is populated from local db table. from there i have to check if there is new data available from web service, if so first i have to update that particular table then UI.
now i need rough idea on how to implement this?
the data from web service isn't going to change frequently. so i need to create some architecture/mechanism where data is always loaded from database first then if new data is available from web service then i parse service update table then update UI.
basically i want something like this
MainThread
|
|
|-------->>--------separate thread----->>-----|
| |
| listener/ query db,
populate UI <<----------- observer/ ------<<----get data
| something |
| |
| |
| |
| check if we have new data--->> if no-- DONE
| |
| if yes
| |
| call web service,
| fetch data,
| update table
| listener/ |
update UI <<-------------observer/-----<<--------|
| something
|
Kinda like Tumblr android App..
now i think i can achieve this with wrapping AsyncTask inside a class and an Interface(as observer/listener)
but i like to use Loader(available in android),
any other suggestion ?
Good question !
It seems that you are trying to achieve the Famous Google I/O design pattern? Google IO Rest design pattern, Finished ContentProvider and stuck now https://www.youtube.com/watch?v=xHXn3Kg2IQE
I did it in the past (maybe as not as well as it should have been done ;-) ). And my advice is be sure of this two points :
If it's not the case, you 'll probably face performance issues due to database accesses. But it's a really good pattern.
Another advice is to use an Event bus instead of boiler-plate, frustrating interfaces for updating the UI . (I usaully use this one https://github.com/greenrobot/EventBus no performance problems, Otto is good and simple too but does not integrate well with android-annotations).
Hope it'll help.