Issue
I have an Activity that launches a Camera Intent like this (nothing special):
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(Environment.getExternalStorageDirectory(), filename);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
Uri imageUri = Uri.fromFile(photo);
startActivityForResult(intent, CAMERA_REQUEST);
Than I get the result in onActivityResult()
and set the bitmap to an ImageView. Again, nothing special.
The problem is that the Camera app is always in landscape. So if the user keeps the device in the horizontal orientation when they hit OK to send it back to my Activity, and my Activity was previously in portrait, then it crashes my activity because it has to rebuild it. If you tilt the device to portrait orientation before you tap OK in the camera, then it does not crash. How do I get around this?
Solution
You need to override the onSaveInstanceState
method to persist the settings of your activity before fit rotates. Then, in the onCreate method, you can check to see if the Bundle
argument is null. If not, then you are recreating your activity and should load the saved settings from it.
Answered By - Brigham
Answer Checked By - Timothy Miller (JavaFixing Admin)