URLからDrawableへの変換注意点

DrawableでOutOfMemoryエラーが起きるのデバッガであるコードの中を追ってみた。

InputStream input = (InputStream) new URL("http://****/hoge.jpg").getcontent();
Drawable draw = Drawable.createFromStream(input, "");

これのコールスタックを見てみると一目瞭然。

BitmapFactory.decodeStream(InputStream, Rect, BitmapFactory$Options)
BitmapFactory.decodeResourceStream(Resources, TypedValue, InputStream, Rect, BitmapFactory$Options) 
Drawable.createFromResourceStream(Resources, TypedValue, InputStream, String, BitmapFactory$Options) 
Drawable.createFromStream(InputStream, String) 

InputStreamからBitmapを作ってました。
縦横のでかい高圧縮なjpegをInputStreamに突っ込んじゃったらそりゃメモリ不足になるよね。という話。