Currently, I have a piece of code, which is designed to run both in Android 2.3 and 4+
The code will perform much better (Where it will not have OutOfMemory exception most of the time), if
android:largeHeap is being applied in AndroidManifest.xml.
<application android:name=".MyApplication" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:screenOrientation="nosensor" android:largeHeap="true"
android:minSdkVersion need to set to 15 instead of 10 (Android 2.3). If not,
android:largeHeap is not allowable in AndroidManifest.xml.
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
Within single APK, how possible I can set
android:largeHeapoption if I were in Android 4+
- Do not use
android:largeHeapoption if I were in Android 2.3
You can also disable large heap in Honeycomb and enable it in ICS or JB. Just a little hacky or something. Here’s what I tried.
Before we proceed, change your Build target to Honeycomb, Jelly Bean or ICS so we can put
android:largeHeap attribute. Also, you can set
API 10 doesn’t support large heap.
- Create a folder
- I created
- Put this value in
boolean value for
values-[API VERSION] >
bools.xml to disable large-heap in different API Version or by default.
Change the value of
@bool/largeheap instead of hardcoded
<application android:largeHeap="@bool/largeheap" android:allowBackup="true" android:icon="@drawable/ic_launcher"> .... </application>
I tested this code by making a memory leak application or just load a Huge bitmaps, and, its working!
android:largeHeap="true" attribute in your
AndroidManifest.xml. This should be ignored for versions that don’t support it. Then, to support older versions, set the heap size using the
VMRuntime class (via reflection, if necessary).
More on this topic: How to increase heap size of an android application?
1.Build project with target Android 3.0 (API 11) or above.
(Project properties – Android – Project Build Target – select above API level 11)
in Manifest file, Change the uses-sdk value as following
For prior versions of Android 3.0, you can use VMRuntime class for memory manipulations.
Seems that you have incorrect target sdk in project.properties file, check it out and change target to your AndroidManifest`s targetSdk (15) and rebuild project.
# Project target. target=15
P.S. I tryed add android:largeHeap to my Project (minSdk = 7, targetSdk = 17) compiled and run normally on all Android versions.
Please change project properties:
In project Properties -> Android -> Project Build Target -> Google API, API level 19 (or any other you need) 🙂
So your can leave your minimum SDK option without change, for example 8 🙂