Sorry for the large code. Thanks for your help. What I would like to
know is when to use weak references and if it is a good option while
using Bitmaps? If so how does it help?

/** This is the onPause function which releases the bitmap when the
imagebutton is clicked and gallery is displayed.
 protected void onPause() {
    super.onPause();
    Log.v(TAG,"on pause called");
    Log.v(TAG,"Allocated memoryin on pause before recycle done:
"+Debug.getNativeHeapAllocatedSize());
        choice.setImageBitmap(null);
        if(bitmap != null)
        {
            Log.v(TAG,"bitmap is not null");
            bitmap.recycle();
            if(bitmap.isRecycled())
                Log.v(TAG,"bitmap is recycled");
            bitmap = null;
        }


        if(mutBitmap != null)
        {
            mutBitmap.recycle();
            if(mutBitmap.isRecycled())
                Log.v(TAG,"mutBitmap is recycled");
            mutBitmap = null;
        }
        Log.v(TAG,"Allocated memory on pause after recycle done:  "
+Debug.getNativeHeapAllocatedSize());
    }
    @Override
    protected void onResume() {
        super.onResume();
        choice.setImageBitmap(bitmap);
    }
  /** call to Gallery Activity **/
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        Log.v(TAG,"onActivityResult called before loading bitmap,
Allocated memory:  "+Debug.getNativeHeapAllocatedSize());


        if (resultCode == RESULT_OK) {
            photoUri  = intent.getData();


            if (photoUri != null) {
                try {
                        Log.v(TAG, "No crash 0");
                       bitmap =
Bitmap.createScaledBitmap(MediaStore.Images.Media.getBitmap(this.getContentResolver(),
photoUri), 300, 400, true);
                       Log.v(TAG, "No crash 1");
                       Log.v(TAG,"onActivityResult called after
loading bitmap,  Allocated memory:
"+Debug.getNativeHeapAllocatedSize());
                      choice.setImageBitmap(bitmap);

                } catch (Exception e) {
                    Log.v(TAG, "Unable to load image at path: " +
photoUri.getPath());
                }
            }
        }


    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to