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. How to modify main.mk to automatically install a sample.apk file into the target image

Hi,
        If I include a project with an android.mk file as follows:

subdir_makefiles += \
./library/SerialLibrary/Android.mk \

It doesn't install the SerialLibrary.apk file to out/target/product/
generic/system/app/SerialLibraryClient.apk

However, if use the mm command as follows, it does everything
correctly:
$ cd android
$ . build/envsetup.sh
$ cd library/SerialLibrary
$ mm

Install: out/target/product/generic/system/app/SerialLibraryClient.apk
Install: out/target/product/generic/system/etc/permissions/
com.company.serial_library.xml
Install: out/target/product/generic/system/framework/
com.company.serial_library.jar
Install: out/target/product/generic/system/lib/
libserial_library_jni.so
make: Leaving directory `/tool/android'

How should I modify main.mk or the SerialLibrary project files to get
it to automatically install, when I build the whole android SDK?

Best regards,

Elvis Dowson


--~--~---------~--~----~------------~-------~--~----~

2. HTC G1 Dream with cupcake STK (SIM Toolkit) not found

No news about STK in HTC Dream?



--~--~---------~--~----~------------~-------~--~----~

3. lock data usage to email

4. Is running applications from shell disabled?

5. new dev device

6. Application (.apk) Size

7. A2DP bluetooth e riproduzione a scatti (music cut)