简体   繁体   English

Android内存不足错误

[英]Android Out of Memory error

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? 有这个例子吗?

how do I use this function within my Activity? 如何在我的活动中使用此功能?

Well, as the function is public static simply: 好吧,因为该函数是public static简单:

 className.getAssetImage(this, yourDrawableName);

without creating an instance of the class className (Utils) 而不创建类className (Utils)instance

ex: 例如:

Drawable mDrawable = Utils.getAssetImage(this, "my_drawable_image_name");

where mDrawable is the Drawable image returned. 其中mDrawable是返回的Drawable图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM