2

I am using the below line to set my ImageView.

    Bitmap bm = Media.getBitmap(getContentResolver(), capturedImage);
                    Bitmap bm1=Bitmap.createScaledBitmap(bm, 300, 300,true);
                    pic.setImageBitmap(bm1);

But when I rotate my mobile, the imageView becomes blank. Can anyone help me. Any help is appreciated.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • I got it to work. Check - http://stackoverflow.com/questions/29191172/imageview-image-lost-on-change-in-orientation/29191883 – Ananth Mar 22 '15 at 07:14

3 Answers3

1

Try adding android:configChanges="orientation|keyboardHidden" to your Activity tag in your AndroidManifest. Take a look here for more details.

Haphazard
  • 10,900
  • 6
  • 43
  • 55
1

Proper way to it is to save the bitmap in onRetainNonConfigurationInstance()

Here is an example: http://developer.android.com/guide/topics/resources/runtime-changes.html

Lumis
  • 21,517
  • 8
  • 63
  • 67
  • 1
    This example uses deprecated methods (getLastNonConfigurationInstance). Try this: http://stackoverflow.com/questions/10831429/orientation-changes-in-android –  Jan 19 '13 at 23:27
0

You should save capturedImage in your onSaveInstanceState method, and then check in your onRestoreInstanceState method to see if you saved it and then re-execute the code you have above. See the answer of Saving Android Activity state using Save Instance State for an excellent example of how this would work.

Community
  • 1
  • 1
Femi
  • 64,273
  • 8
  • 118
  • 148
  • I tried using this. But still if I rotate my mobile for two times the image becomes null. I get the same problem. It looks persistent only for first orientation change. Is there any other way that I could try. – Andro Selva May 25 '11 at 05:18
  • That really is the best way to do it: you may have an error in your implementation. If we post the code you are using in `onSaveInstanceState` and `onRestoreInstanceState` we might be able to point out the changes you need to make to fix the issue you're seeing. – Femi May 25 '11 at 05:21
  • @Lumis solution might be somewhat more efficient. – Femi May 25 '11 at 05:22