我正在尝试通过缓存图片并在滚动列表时从手机加载图片而不是从互联网加载来加速我的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。针对这些图片,最好的序列化方法是什么?