[英]what happen when memory is full in image gallery
有一個圖庫應用程序可以在線下載圖像。 我想知道手機內存/ SD卡裝滿會怎樣? 如果出現錯誤,該怎么辦?
如果sdcard中沒有剩余內存,它將通過IOException。 但是,如果您知道要下載的文件大小,則可以檢查是否有足夠的內存,從而可以避免IOException。
編輯: 捕獲異常
try
{
//your code here
}
catch(IOException ex)
{
//do stuff when exception caused.
}
如果您不知道如何使用/捕獲異常。 請用谷歌搜索。
這會捕獲OutofMemory錯誤,但也應該檢查其他異常
URL aURL = null;
Bitmap bm = null;
try {
final String imageUrl = CMSServer + url;
aURL = new URL(imageUrl);
URLConnection conn = aURL.openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
is = new BufferedInputStream(conn.getInputStream());
bm = BitmapFactory.decodeStream(is, null, options);
is.close();
} catch (OutOfMemory oom) {
// do something
}
}
return bm;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.