0

Hi When i start Activity first time it will work properly but when i start it again, i will get bitmap size exceeds VM budget

my code is below

public class TemplateList extends BaseActivity {

ImageUtil imgUtil;
private GridView gridView;
private LinearLayout layoutInflate;
private String Url;
public ArrayList<ArrayList<picitem>> data;
public ImageLoader1 imageLoader;
AlertMessages messages;

private ProgressDialog pd;
Thread thread = null;
private Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        if (pd != null)
            pd.dismiss();
        if (msg.what == 11) {
            try {
                fillList();
            } catch (Exception e) {
                Toast.makeText(TemplateList.this, "An error has occured", Toast.LENGTH_LONG).show();
            }
        } else if (msg.what == 0) {

        } else if (msg.what == 1) {

        } else if (msg.what == 25) {

        } else {
            messages.showNetworkAlert();
        }
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.framegrid);

    btnHome = (Button) findViewById(R.id.btnHome);
    btnPostGard = (Button) findViewById(R.id.btnPostGard);
    btnDrake = (Button) findViewById(R.id.btnDrake);
    btnFacebook = (Button) findViewById(R.id.btnFacebook);

    gridView = (GridView) findViewById(R.id.gridFrame);

    btnHome.setBackgroundResource(R.drawable.home);
    btnPostGard.setBackgroundResource(R.drawable.postcardup);
    btnDrake.setBackgroundResource(R.drawable.drake);
    btnFacebook.setBackgroundResource(R.drawable.facebbook);

    imgUtil = new ImageUtil();
    messages = new AlertMessages(this);
    layoutInflate = (LinearLayout) findViewById(R.id.layoutinflate);

    imageLoader = new ImageLoader1(getApplicationContext(), Url);

    data = new ArrayList<ArrayList<picitem>>();
    fillData();
}

private void fillList() {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (int i = 0; i < data.size(); i++) {

        View customView = inflater.inflate(R.layout.cutomviewhorizontal, null);
        LinearLayout layoutHorizontalScroll = (LinearLayout) customView.findViewById(R.id.customhoriview);
        TextView txtCategory = (TextView) customView.findViewById(R.id.txtCategoryInflate);
        System.out.println();
        txtCategory.setText(data.get(i).get(0).getCategoryName()+" Templete");
        ArrayList<picitem> items = data.get(i);         
        for (int j = 0; j < items.size(); j++) {
            View customView1 = inflater.inflate(R.layout.imginflate, null);
            final ImageView img = (ImageView) customView1.findViewById(R.id.imgCategoryInflate);
            img.setTag(items.get(j).getThumbImagePath().toString().trim());
            final String imagepathString=items.get(j).getImagePath().toString().trim();
            imageLoader.DisplayImage(items.get(j).getThumbImagePath().toString().trim(), this, img);

            img.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(TemplateList.this, PictureEditor.class);
                    Bundle b = new Bundle();
                    b.putString("Key", "2");
                    b.putString("Index", imagepathString);
                    i.putExtras(b);
                    v.getContext().startActivity(i);
                    finish();
                }
            });

            layoutHorizontalScroll.addView(customView1);
        }

        layoutInflate.addView(customView);
        }
}

private void fillData() {
    if (Utils.isOnline(TemplateList.this)) {

        pd = ProgressDialog.show(TemplateList.this, "", "Loading...", true, false);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Parsing p = new Parsing();
                    data = p.getList();
                    handler.sendEmptyMessage(11);
                } catch (Exception e) {
                    e.printStackTrace();
                    handler.sendEmptyMessage(0);
                }
            }
        }).start();
    } else {
        messages.showNetworkAlert();
    }
}

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

}

My Logcat is below

   12-19 16:30:52.069: E/AndroidRuntime(11442): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
   12-19 16:30:52.069: E/AndroidRuntime(11442):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
   12-19 16:30:52.069: E/AndroidRuntime(11442):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
  12-19 16:30:52.069: E/AndroidRuntime(11442):  at com.redwood.ImageLoader1.decodeFile(ImageLoader1.java:145)
   12-19 16:30:52.069: E/AndroidRuntime(11442):     at com.redwood.ImageLoader1.getBitmap(ImageLoader1.java:103)
  12-19 16:30:52.069: E/AndroidRuntime(11442):  at com.redwood.ImageLoader1.access$0(ImageLoader1.java:96)
  12-19 16:30:52.069: E/AndroidRuntime(11442):  at com.redwood.ImageLoader1$PhotosLoader.run(ImageLoader1.java:200)
Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150
  • 1
    when you jump from 1st activity to second The 1st activity goes in pause Mode and start new activity and when you go from 2nd to 1st activity the previous activity data is already in the Memory and it loads that data again and engulf heap size and cause crash – Usman Kurd Dec 19 '12 at 11:48
  • Please post the code of `startClick()`, where we should find the memory leak. – Sébastien Dec 19 '12 at 13:49
  • Does this answer your question? [java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android](https://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android) – Ryan M Jul 07 '21 at 21:50

0 Answers0