【发布时间】:2011-10-05 06:28:37
【问题描述】:
我正在尝试通过缓存图像并在滚动列表时从手机而不是互联网加载它们来加速我的 ListView。但是,当我尝试序列化 Drawable 对象时遇到了异常。这是我的功能:
private void cacheImage(Drawable dr, Article a){
FileOutputStream fos;
try {
fos = openFileOutput(a.getArticleId().toString(), Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(dr);
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
这段漂亮的代码导致:
java.io.NotSerializableException: android.graphics.drawable.BitmapDrawable
序列化这些图像的最佳方法是什么?
【问题讨论】:
标签: android serialization drawable