0

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.