0

I have two arraylist objects:

public static List< Bitmap> homeImages;
public static List< WPListModel> newslistitems;

These list store the data by getting it from server, it store all images in homeImages and textual data in newslistitems...

Now my question is whenever I open my Android App, it hits on server and store data in arraylists and display it, I want to store data in cache so whenever I open the App then first it checks in cache, if data is present then it will show otherwise normal procedure(hit on server and get the data) and if data is present then it will show the data and after opening the app it gets the latest data(after opening).

Guillaume Algis
  • 10,705
  • 6
  • 44
  • 72
Waqas Shahid
  • 1,051
  • 1
  • 7
  • 22

1 Answers1

2

Store these array lists in files and stored them in the folder from Activity.getCacheDir(). When your app starts, look for data in that folder first. If it is not empty, then load from there. Otherwise, load from server.

hfann
  • 599
  • 3
  • 13
  • If you can provide me some source code, it will be appreciatable coz I'm new on Android Development and I have to edit somebody else's code :) – Waqas Shahid Apr 28 '14 at 15:22
  • @user3202674 How you save your data to file depends on your data structure. You can use text file (OutputStreamWriter), XML (XmlSerializer), binary file (DataOutputStream), or even Sqlite database (SQLiteDatabase). To save bitmap to a file, check [here for sample code](http://stackoverflow.com/questions/11274715/save-bitmap-to-file-function). Search SO for code. – hfann Apr 28 '14 at 17:10