Android 出现 OutOfMemoryError 的一种解决方法

OutOfMemoryError是Android处理位图时最常见的问题。当由于缺少内存空间而无法分配对象时以及垃圾回收器无法释放一些空间时,Java虚拟机(JVM)也会抛出此错误。

一种解决办法是在AndroidManifest文件中加入:

android:hardwareAccelerated="false"
android:largeHeap="true"

例如如下的AndroidManifest文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.toby.personal.testlistview">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"

        android:hardwareAccelerated="false"
        android:largeHeap="true"

        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容