Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:57:12+00:00 2026-06-11T14:57:12+00:00

I’ve been working on this ap for a client. We are pretty much ready

  • 0

I’ve been working on this ap for a client. We are pretty much ready to release it, but in testing I realize it crashes pretty much at any point onPause(), onResume() are called. Specifically getting a text, or rotating the screen. Or in some cases simply going between screens. Every time it gives me an out of memory error. So obviously the images for the background, buttons etc, are to blame, as they are the only elements that use any real amount of memory. So I’ve stripped it down to a completely bland application with just 2 buttons with images on it.

The buttons are 60k PNGs which have been optimized for mobile devices via photoshop.

I have done a lot of research, and spent time in #android-dev on freenode. I’m not seeing anything to fix this problem.

I process the background according to the documents on the android dev. This part is not in this code, but otherwise it would be immanently added to the onCreate() method as soon as I can get it to work with a blank ap with 2 buttons. (with the appropriate view)

currently not in the application, but will be added back

private void setNewPoolBackground() {
    setContentView(<FOO>);
    Bitmap image = getImage(R.drawable.background);
    Drawable d = new BitmapDrawable(image);
    rLayout = (RelativeLayout) findViewById (<FOO>);
    rLayout.setBackgroundDrawable(d);
}
private Bitmap getImage(int img) {
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    // The new size we want to scale to
    final int REQUIRED_SIZE = 70;
    // Find the correct scale value. It should be the power of 2.
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    while (true) {
        if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }
    Bitmap image = BitmapFactory.decodeStream(this.getResources()
            .openRawResource(img), null, o2);
    return image;
}

CODE: TestRotation.java

package test.t;


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class TestRotateActivity extends Activity {

    Bitmap image;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //setNewPoolBackground();
    }


    @Override
    protected void onPause() {
        super.onPause();
        // saveState();
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        //View v 
        super.onStop();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // TODO Auto-generated method stub

    }

}

main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/group_edit"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5pt"
        android:layout_marginLeft="8pt"
        android:layout_marginRight="7pt"
        android:layout_marginTop="50pt"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp" 
        android:isScrollContainer="false"
        >

        <LinearLayout
            android:id="@+id/linlayGN"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >






            <TextView
                android:id="@+id/tvGroupTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="group_title" />

            <EditText
                android:id="@+id/group_title"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <requestFocus />
        </LinearLayout>

        <ScrollView
            android:id="@+id/ScrollView01"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:isScrollContainer="false"
         >


            <LinearLayout
                android:id="@+id/newUserList"
                android:layout_width="233dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/group_title"
                android:layout_weight="2.44"
                android:orientation="vertical" >

            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <Button
        android:id="@+id/addgbutton"
        android:layout_width="40pt"
        android:layout_height="25pt"
        android:layout_alignLeft="@+id/moremembutton"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="28dp"
        android:layout_marginLeft="64dp"
        android:background="@drawable/finish"
        android:onClick="myClickHandler" >
    </Button>

    <Button
        android:id="@+id/moremembutton"
        android:layout_width="40pt"
        android:layout_height="25pt"
        android:layout_alignBottom="@+id/addgbutton"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="22dp"
        android:layout_marginLeft="81dp"
        android:background="@drawable/addmember"
        android:onClick="myClickHandler" >
    </Button>

</RelativeLayout>

LOG

09-19 03:17:57.546: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 806 objects / 56864 bytes in 45ms
09-19 03:17:57.876: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 206 objects / 9736 bytes in 37ms
09-19 03:19:00.135: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 707 objects / 25800 bytes in 94ms
09-19 03:19:00.545: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 28 objects / 1624 bytes in 33ms
09-19 03:19:06.885: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 597 objects / 24008 bytes in 37ms
09-19 03:19:07.605: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 523 objects / 31384 bytes in 32ms
09-19 03:19:07.916: D/dalvikvm(278): GC_EXTERNAL_ALLOC freed 84 objects / 3816 bytes in 32ms
09-19 03:19:19.346: E/dalvikvm-heap(278): 3122676-byte external allocation too large for this process.
09-19 03:19:19.355: E/GraphicsJNI(278): VM won't let us allocate 3122676 bytes
09-19 03:19:19.375: D/AndroidRuntime(278): Shutting down VM
09-19 03:19:19.375: W/dalvikvm(278): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-19 03:19:19.455: E/AndroidRuntime(278): FATAL EXCEPTION: main
09-19 03:19:19.455: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.t/test.t.TestRotateActivity}: android.view.InflateException: Binary XML file line #70: Error inflating class <unknown>
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3815)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread.access$2400(ActivityThread.java:125)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.os.Looper.loop(Looper.java:123)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-19 03:19:19.455: E/AndroidRuntime(278):  at java.lang.reflect.Method.invokeNative(Native Method)
09-19 03:19:19.455: E/AndroidRuntime(278):  at java.lang.reflect.Method.invoke(Method.java:521)
09-19 03:19:19.455: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-19 03:19:19.455: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-19 03:19:19.455: E/AndroidRuntime(278):  at dalvik.system.NativeStart.main(Native Method)
09-19 03:19:19.455: E/AndroidRuntime(278): Caused by: android.view.InflateException: Binary XML file line #70: Error inflating class <unknown>
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
09-19 03:19:19.455: E/AndroidRuntime(278):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-19 03:19:19.455: E/AndroidRuntime(278):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.Activity.setContentView(Activity.java:1647)
09-19 03:19:19.455: E/AndroidRuntime(278):  at test.t.TestRotateActivity.onCreate(TestRotateActivity.java:21)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-19 03:19:19.455: E/AndroidRuntime(278):  ... 12 more
09-19 03:19:19.455: E/AndroidRuntime(278): Caused by: java.lang.reflect.InvocationTargetException
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.widget.Button.<init>(Button.java:65)
09-19 03:19:19.455: E/AndroidRuntime(278):  at java.lang.reflect.Constructor.constructNative(Native Method)
09-19 03:19:19.455: E/AndroidRuntime(278):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
09-19 03:19:19.455: E/AndroidRuntime(278):  ... 23 more
09-19 03:19:19.455: E/AndroidRuntime(278): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.Bitmap.nativeCreate(Native Method)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.content.res.Resources.loadDrawable(Resources.java:1709)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.view.View.<init>(View.java:1885)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.widget.TextView.<init>(TextView.java:327)
09-19 03:19:19.455: E/AndroidRuntime(278):  at android.widget.Button.<init>(Button.java:69)
09-19 03:19:19.455: E/AndroidRuntime(278):  ... 27 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:57:13+00:00Added an answer on June 11, 2026 at 2:57 pm

    OOM error is not an unexpected exception in android if we are playing with lot of bitmap and large images.Since android phones and tab come in many heap sizes its bit difficult to make it compactible with all the deveices.Most of the android devices have low heap memory.through code we can allocate it because we only have limited acess to clear the memory.After each process call the System.gc() and alocate the unused memory using garbagecollector.Still its not sure that all the unused memory is cleared.Recycle all the bitmaps after your usage bitmap.recycle().Also dont use many bitmaps in the app.Built an app with very less number of bitmaps,when you use it recycle it and use it again and again.
    You can unbind all the drawables from the views when you leave an activity.

    private void unbindDrawables(View view) {
            if (view.getBackground() != null) {
                try {
                    view.getBackground().setCallback(null);
                    ((BitmapDrawable) view.getBackground()).getBitmap().recycle();
                    view.destroyDrawingCache();
                    view.notifyAll();
                } catch (Exception e) {
                }
    
            }
            if (view instanceof ViewGroup) {
                for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                    unbindDrawables(((ViewGroup) view).getChildAt(i));
                }
                ((ViewGroup) view).removeAllViews();
            }
        }
    

    You can also deallocate all the unused memory through code..

    public void clearAllocatedMemory() {
            try {
                List.removeAllViews();
                adapter.releaseAllMemory();
            } catch (Exception e) {
            }
            adapter = null;
        }
    

    I think doing all these will allocate your memory to the maximum and you can reduce the chances of this exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.