OutOfMemory: Recycle Images

前端 未结 3 1799
借酒劲吻你
借酒劲吻你 2020-12-04 03:39

I created a photoalbum. I\'ve got 70 activities and in everyone is one Image (jpeg, png). And two arrows to go Back and forth. The Images are saved in drawable-folder. I kno

相关标签:
3条回答
  • 2020-12-04 03:59

    Add this in your AndroidMainfest.xml file:

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

    inside applicaton tag like this:

    <application
            android:hardwareAccelerated="false"
            android:largeHeap="true"
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    0 讨论(0)
  • 2020-12-04 04:18

    The problem is that you don't finish previous activities, that's why recycle bitmap doesn't help. If you want to continue implement gallery in this way you can set image in onStart and remove it in onStop or override back button, finish and track your activities and relaunch them when back pressed.

    0 讨论(0)
  • 2020-12-04 04:19

    First of all you should scale your images down,this decreases the amount of memory used.Here's a good tutorial on that: Loading large bitmaps efficiently

    Then you should only have the one picture that is displayed inside your memory. So before starting the new activity recycle your Bitmap and set it to null, the gc will take care of it.

    0 讨论(0)
提交回复
热议问题