Asked  7 Months ago    Answers:  5   Viewed   56 times

I am writing an Android application which uses several 3D models. Such a model with textures can take up a lot of memory. I found out the manufacturer sets a limit on the heap size an application can use. For example my tablet Samsung Galaxy Tab 8.9 P7310 can take up 64MB of memory.

Is there a way to increase this size of memory an application can use?



You can use android:largeHeap="true" to request a larger heap size, but this will not work on any pre Honeycomb devices. On pre 2.3 devices, you can use the VMRuntime class, but this will not work on Gingerbread and above.

The only way to have as large a limit as possible is to do memory intensive tasks via the NDK, as the NDK does not impose memory limits like the SDK.

Alternatively, you could only load the part of the model that is currently in view, and load the rest as you need it, while removing the unused parts from memory. However, this may not be possible, depending on your app.

Tuesday, June 1, 2021
answered 7 Months ago

Instead of increasing heap size you can do some thing better. As you said that you are maintaining cache in you application which is implemented using SoftReferences. The best thing is to use LruCache you can do some thing like this:

private LruCache<String, Bitmap> bitmapCache;
final int memClass;
int cacheSize;

memClass = ((ActivityManager) context.getSystemService(

Return the approximate per-application memory class of the current device. This gives you an idea of how hard a memory limit you should impose on your application to let the overall system work best. The returned value is in megabytes; the baseline Android memory class is 16 (which happens to be the Java heap limit of those devices); some device with more memory may return 24 or even higher numbers.

cacheSize = 1024 * 1024 * memClass / 10;
bitmapCache = new LruCache<String, Bitmap>(cacheSize) {
  protected int sizeOf(String key, Bitmap value) {
    return value.getHeight() * value.getRowBytes();

it will remove the bitmap images from LruCache if the memory exceeds the located memory to LruCache and load the new image in it.

Thursday, July 29, 2021
answered 4 Months ago

You will need to use PackageManager to get the package information about whatever app you select in the list. I haven't done this with a Spinner but i'm sure it should work the same as it did in my ListView.

appspinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View arg1,
                int app_pos, long app_id) {
        // TODO Auto-generated method stub
        String app_selected=parent.getItemAtPosition(app_pos).toString();

        final PackageManager pm = getPackageManager();
        //get a list of installed apps.
        List<ApplicationInfo> packages = pm.getInstalledApplications(
        int UID;
        //loop through the list of installed packages and see if the selected
        //app is in the list
        for (ApplicationInfo packageInfo : packages) {
                //get the UID for the selected app
                UID = packageInfo.uid;
                break; //found a match, don't need to search anymore


        //Do whatever with the UID
        Log.i("Check UID", "UID is: " + UID);               


    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

You might want to see how packageName returns the packageName so you can try to match it with whatever was selected.

hope this points you in the right direction and helps you out. Good Luck.

Friday, July 30, 2021
answered 4 Months ago

Set your compileSdkVersion 'android-P' and targetSdkVersion 28

EDIT: Now compileSdkVersion 28 should also work meaning you no longer have to set it to android-P

Saturday, September 18, 2021
answered 3 Months ago

Purely by guessing, I changed the following in my gradle config


  testOptions {


  testOptions {

and all seems to work.

Sunday, September 19, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :