Android提供了一些保存应用程序信息的方法。 http://developer.android.com/guide/topics/data/data-storage.html
现在,我的问题是我有一些与任务相当的结构化数据,这些数据具有类别和一些其他相关设置。所有内容均从 Web 服务获取,并且必须保存以提高性能和离线使用。
哪个是在 Android 上使用的最佳选项?我认为实际上是在 SQLite 数据库或内部存储之间进行选择。选择其中一个选项,我对性能和实现有何期望?
最佳答案
缓存数据的一种非常简单的方法是序列化对象并将它们保存到内部缓存,例如:
// Example object which implements Serializable
Example example = new Example();
// Save an object
ObjectOutput out = new ObjectOutputStream(new FileOutputStream(new File(getCacheDir(),"")+"cacheFile.srl"));
out.writeObject((Example) example);
out.close();
// Load in an object
ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(new File(getCacheDir(),"")+"cacheFile.srl")));
Example example_loaded = (Example) in.readObject();
in.close();
关于java - 在android中保存结构化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7105687/