Best Way to Cache Data in Android

前端 未结 3 1990
日久生厌
日久生厌 2021-01-30 05:52

I have an ArrayList of custom, simple Serializable objects I would like to cache to disk and read on re-launch. My data is very small, about 25 object

3条回答
  •  囚心锁ツ
    2021-01-30 06:01

    For what it worth I cache some of my String data to disk using BufferedWriter/BufferedReader and it's very fast. Matter of fact it is faster than storing the same data to SharedPreferences. The code goes something like this (note that things happen faster when you provide buffer size)

    final BufferedWriter out = new BufferedWriter(new FileWriter(file), 1024);
    out.write(stuff);
    out.close();
    

提交回复
热议问题