Switching orientation crashes app with larger image.

by darrinps » Sun, 07 Nov 2010 00:32:25 GMT


Sponsored Links
 I have an application that works fine with smaller images (say
1024x768 or so) but when you rotate the phone into a different
orientation (say landscape to portrait) mode with a larger image on
the screen, and then call ImageView.setImageUri() it goes into the
BitmapFactory.class and never returns!

So the app eventually times out. Never throws an exception, just never
returns.

My code looks like this

        ImageView image1 = (ImageView)
findViewById(R.id.ImageView_HeaderPlay1);
        ImageView image2 = (ImageView)
findViewById(R.id.ImageView_HeaderPlay2);

        image1.setAdjustViewBounds(true);
        image2.setAdjustViewBounds(true);

        //Get the max size of the device
        Display display = ((WindowManager)
getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width  = display.getWidth();
        int height = display.getHeight();
        int max = width > height ? height : width;

        max = max / 10;

        image1.setMaxHeight(max);
        image1.setMaxWidth(max);
        image1.setImageURI(selectedImageUri);

        image2.setMaxHeight(max);
        image2.setMaxWidth(max);

                try
                {
                        image2.setImageURI(selectedImageUri);  <-----DIES
with this call

                        TextView textView = (TextView) 
findViewById(R.id.lblEnterText);
        
textView.setText(getResources().getString(R.string.image_instructions));
                }
                catch(Exception e)
                {
                        Log.i("ERROR", "Exception caught trying to set text: " 
+ e);
                }
        }

Has anyone else seen this? Sounds like a bug in the Android code more
than something I am doing since it works fine for smaller images.

--



Switching orientation crashes app with larger image.

by Kumar Bibek » Sun, 07 Nov 2010 04:20:33 GMT


 No exception thrown? Are you sure your logcat doesn't say anything?

I suspect, you might be getting OutOfMemoryException.
Have you considered scaling your image? Or, do you have to preserve
this resolution?
If you can scale your images, perhaps, you can avoid it.




--


Sponsored Links


Switching orientation crashes app with larger image.

by hoyski » Tue, 09 Nov 2010 02:54:33 GMT


 I suspect an OutOfMemoryException as well.

Unless you truly need to reload the image, consider using
onRetainNonConfigurationInstance()/getLastNonConfigurationInstance()
to preserve your already loaded image when the orientation changes.





--