views:

327

answers:

2

I have a very small activity that must show an image.

If picture is not very small (for example 1.12 Mb 2560x1920) it produces out of memory on change screen orientation. I tried getDrawable.setCallback(null) but no luck.

Where am I wrong?

public class Fullscreen extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    System.gc();
    setContentView(R.layout.fullscreen);
    ImageView imageView = (ImageView) findViewById(R.id.full_screen_image);
    long imageId = 2;
    imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageId));
    }
}
+1  A: 

Consume less memory and downsample/resize(see documentation of BitmapOptions#inSampleSize) the picture.

Samuh
Code sample here http://stackoverflow.com/questions/477572/823966#823966
Fedor
+1  A: 

Your application must be leaking context. That's usually the reason why application crashes after several orientation changes. Read this carefully http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html.

Fedor