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?

Community
  • 1
  • 1
user1353517
  • 300
  • 3
  • 10
  • 28

1 Answers1

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.

hrskrs
  • 4,447
  • 5
  • 38
  • 52