我有一个包含大量数据的 ListView。
第一次,我从 Web 服务加载所有数据。
现在我想缓存该数据,这样,如果我再次打开该页面,我可以从缓存中获取数据,而不是再次查询网络服务。
我该怎么做?
最佳答案
我假设您将从 WebService
检索到的数据存储在一个可序列化的对象中(正如您在编辑之前在问题中所述。)
您可以将可序列化对象存储到一个文件中并稍后加载它们:
商店:
FileOutputStream fileOutputStream = yourContext.openFileOutput(fileName, Context.MODE_PRIVATE);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(yourObject);
objectOutputStream.close();
加载:
FileInputStream fileInputStream = yourContext.openFileInput(fileName);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
Object yourObject = (Object)objectInputStream.readObject();
objectInputStream.close();
关于android - Android中ListView缓存的实现方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15154164/