I am not sure whether “cache” is the right term to use or not but here goes my question, in my app i have an activity which loads JSON data from Internet and then populates a list view which seems to be working fine.
The real problem is the moment is loose Internet connection it starts showing a blank screen , is there any way i could keep on showing the old list view which was generated earlier in case there is no Internet connection and fetch the data only if there is persistent connection.
I know how to find whether there is net connection or not , so please do not write code for that my main concern is to save the previously loaded list views and display them if no connection found.
The only thing i can think of right now is making use of local sqlite database.
This way, your list will then be updated if and only if you have an internet connection.
Why onResume() and not onCreate()? When you come back from another activity, the activity onResume() itself 😉
For the user-friendly part, I do not know when you do this “update” but avoid doing it by yourself. Action bar (or menus) are here to let the user update data when he wants to.
For the user-friendly part II. If you think the user MUST not play with you list while you are updating, disable events on that list or, if the user MUST not do anything (your app is to manipulate objects from that list), make use of a progress dialog to notify the user you are doing something