I'm using this answer to help solve my out of memory issue. The solution was to move all the drawables to a new drawable folder inside the assets folder and use this function
public static Drawable getAssetImage(Context context, String filename) throws IOException {
AssetManager assets = context.getResources().getAssets();
InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".png")));
Bitmap bitmap = BitmapFactory.decodeStream(buffer);
return new BitmapDrawable(context.getResources(), bitmap);
}
My question is how do I use this function within my Activity? Is there an example of this?
asked Mar 16, 2015 at 15:51
user1353517
3004 gold badges10 silver badges28 bronze badges
1 Answer 1
how do I use this function within my Activity?
Well, as the function is public static simply:
className.getAssetImage(this, yourDrawableName);
without creating an instance of the class className (Utils)
ex:
Drawable mDrawable = Utils.getAssetImage(this, "my_drawable_image_name");
where mDrawable is the Drawable image returned.
answered Mar 16, 2015 at 15:53
hrskrs
4,5085 gold badges40 silver badges52 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-java