我試圖通過緩存圖像並在滾動列表時加載它們從手機而不是互聯網加速我的ListView。但是,當我試圖序列化Drawable對象時,我遇到了異常。這是我的函數:序列化Android上的Drawable對象
java.io.NotSerializableException:
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();
}
}
的代碼導致這個漂亮位android.graphics.drawable.BitmapDrawable
什麼是序列化的最佳方法這些圖像?
這似乎工作,但我將如何去讀取存儲的圖像回到我的應用程序? – karl