Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android's large heap option work for older phones upgraded to ICS?

I've got a Galaxy Nexus myself, and I know that the android:largeHeap="true" manifest option works on this phone, but I was wondering if it's working on older phones that are being upgraded to Ice Cream Sandwich, i.e. the Samsung Nexus S.

The reason why I'm asking is that I've built an application that makes heavy use of large bitmaps and the application was originally designed for tablets with 48 MB of heap size. The Galaxy Nexus also features 48 MB of available heap size for each application, so my application is working beautifully on this phone despite it not being a tablet.

The problem is that the Nexus S only has 32 MB of heap available, so I really need the large heap option for the application to work on these older phones with ICS.

My question: Does the android:largeHeap option still increase the of available heap memory? I.e. if the Nexus S has 32 MB by default, will I be able to access perhap 64 MB available by using this?

For those of you unfamiliar with this option, it increases the amount of available heap memory for your application at the cost of lower performance. It should only be used when there's no other alternative.

Update

Here's the application package to show your available heap size: http://michellbak.dk/TestHeapSize.apk

The source code is below to show you that there's nothing harmful:

package com.miz.heapsize;

import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView text;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ActivityManager am = ((ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE));
        int memory = am.getMemoryClass();
        int largeMemory = am.getLargeMemoryClass();

        text = (TextView) findViewById(R.id.textView1);
        text.setText("Normal heap size: " + memory + "\nLarge heap size: " + largeMemory);

    }
}

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.miz.heapsize"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true" >
        <activity
            android:label="@string/app_name"
            android:name=".MainActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
like image 713
Michell Bak Avatar asked Dec 30 '11 00:12

Michell Bak


1 Answers

The android:largeHeap option is available on all devices running Android 3.0 or above. This includes devices that have been upgraded to ICS.

That said, you're not guaranteed to get 48 MB of space. The exact heap size provided to applications is an option device manufacturers can set on a per-device basis. In general, devices with a larger display will be configured with larger heap sizes.

like image 121
Trevor Johns Avatar answered Nov 18 '22 13:11

Trevor Johns