My app consumes too much RAM, sometimes closed with java.lang.OutOfMemoryError:

My app consumes too much RAM, sometimes closed with java.lang.OutOfMemoryError:

[这是应用启动的时间][1] [这是在打开 Activity 或进行一些操作后,内存保持在 460mb 以上][2]2

这是我的清单:

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

    <!-- Permisos de la aplicaion -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application
        android:allowBackup="true"
        android:hardwareAccelerated="false"
        android:largeHeap="true"
        android:name="android.support.multidex.MultiDexApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@drawable/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!-- Splash Screen -->
        <activity
            android:name=".SplashScreenActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".DonateMainLayout" />
        <activity android:name=".VideoListActivity" />
        <activity
            android:name=".VideoActivity"
            android:screenOrientation="landscape"
            android:theme="@style/videoPlayer" />
        <activity android:name=".RateActivity" />

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />

        <activity android:name=".BMI" />
        <activity android:name=".Result_BMI" />
        <activity
            android:name=".Video_Stream"
            android:screenOrientation="landscape"
            android:theme="@style/videoStream" />
        <activity
            android:name=".Timer_CountDown"
            android:theme="@style/AppTheme.Transparent" />
        <activity
            android:name=".ActivityList1"
            android:label="@string/list1_label" />
        <activity
            android:name=".ActivityList2"
            android:label="@string/list2_label" />
        <activity
            android:name=".ActivityList3"
            android:label="@string/list3_label" />
        <activity
            android:name=".ActivityList4"
            android:label="@string/list4_label" />
        <activity
            android:name=".ActivityList5"
            android:label="@string/list5_label">

        </activity>
        <activity
            android:name=".IntroActivity"
            android:label="@string/intro_title">

        </activity>
        <activity
            android:name=".TipsActivity"
            android:label="@string/tips_title">

        </activity>
        <activity android:name=".DietPlanMain"
            android:label="@string/diet_title">

        </activity>
    </application>

</manifest>

这是我的 gradle:

    apply plugin: 'com.android.application'
repositories {
    maven {
        url 'https://maven.google.com'
    }
}
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.nexttip.personaltrainer"
        minSdkVersion 19
        targetSdkVersion 26
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'me.itangqi.waveloadingview:library:0.3.5'
    compile 'com.android.support:support-compat:26.1.0'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:11.8.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'

在应用程序中,我在数组中有一些视频,还有一些视频是从服务器加载的,我还使用 gif 图像和其他资源。我已经压缩了资源以查看我是否没有问题但是当 运行 应用程序在范围较小的移动设备上时,它会因内存不足而关闭。我使用 Samung s7 进行 4gb ram 的测试,即便如此,当更改 activity 时也会使其变慢。请帮助我

您不应在应用程序中保留一系列视频。相反,您可以保留视频文件的路径和 url 并且一次只加载一个需要播放的视频。也尝试使用图像缓存库,如 Picasso 或 Glide,它们也会解决大图像的内存问题。