Reputation: 23
I searched a lot before writing the question. I have an Intent to pick an image from the camera with extra_output to store in the Uri
When the image is caught in portrait and / or without automatic rotation works perfectly. However if you are in landscape and automatic rotation SOME models gives me error.
My Intent code:
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
startActivityForResult(camera, REQUEST_CAMERA);
My onActivityResult fragment code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ImageView imageFoto = (ImageView) findViewById(R.id.imageIncidenciaDetail);
imatgeOriginal = null;
if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK) {
//if(imageFile != null)
imatgeOriginal = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
I actually have two different errors:
java.lang.RuntimeException: Unable to resume activity {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2928)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3865)
at android.app.ActivityThread.access$700(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1346)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3488)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2883)
... 13 more
Caused by: java.lang.NullPointerException
at com.vicopo.com.lapoblainfo.incidencia_detail.onActivityResult(incidencia_detail.java:145)
at android.app.Activity.dispatchActivityResult(Activity.java:5311)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3484)
... 14 more
And
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3135)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3178)
at android.app.ActivityThread.access$1100(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.vicopo.com.lapoblainfo.incidencia_detail.onActivityResult(incidencia_detail.java:145)
at android.app.Activity.dispatchActivityResult(Activity.java:4663)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3131)
... 11 more
And Android Manifest activity code:
<activity
android:name=".incidencia_detail"
android:label="@string/title_activity_incidencia_detail"
android:screenOrientation="portrait"
android:configChanges="orientation"
>
I can do an if and and check that the image is not null. If I do that app not crash, but the image is null.
Upvotes: 2
Views: 1806
Reputation: 183
Save the imageFile
path on the saveInstanceState(Bundle out)
of your Activity
and restore the imageFile
at the onCreate(Bundle savedInstanceState)
, if savedInstanceState != null
. You may need to store the imageFile
as a String
in order to save it to the Bundle
.
Upvotes: 2