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.





--



Other Threads

1. OutOfMemoryError, but there's lots of memory?!

My app is building a relatively large structure ("large" being a term
that is meaningless without context), and I am getting an
OutOfMemoryError.  Problem is, I'm watching the memory using every
metric I can think of, and I don't see how the error was triggered.
It's obviously trying to allocate a 65kB HashSet in a rehash
operation:

06-06 17:59:11.234: ERROR/dalvikvm-heap(1884): Out of memory on a
65552-byte allocation.

Which makes sense; I traced it to the HashSet operation it is
performing.  But this is what the memory looks at:

ActivityManager.Memory Info: availMem: 26300416B, 26300KB, 26MB
ActivityManager.Memory Info: threshold/lowMemory: 16777216  false
Runtime.freeMemory: 1828856B, 1829KB, 2MB
Runtime.totalMemory: 15605728B, 15606KB, 16MB
Debug memory allocated/native/default: 4452208  1032336  5484544

I don't get it.  Why won't it make a measly 65kB heap?  How can I
detect memory problems given these utilities if they always return
extremely large values right before and after an OutOfMemoryError?
Are there yet additional memory utilities I should be using?

Thank you for any help.
--~--~---------~--~----~------------~-------~--~----~

2. What should be the configuration contents of pvlogger.txt to get the traces from modules of \pvmi\recognizer\plugins?

As we enter 8,PvPlayerEngine in the pvlogger.txt to get the traces
from PVplayerEngine what should be the configuration contents of
pvlogger.txt for the modules preset in \pvmi\recognizer\plugins?
--~--~---------~--~----~------------~-------~--~----~

3. Sample code for obtaining location-on-demand that accounts for life cycle?

4. Scala with Android 1.5

5. Debug Appwidget using Eclipse/ADT

6. Multiple ItemizedOverlay conflicts

7. PhoneStateListener question