PieterVanPoyer commented on issue #665: URL: https://github.com/apache/cordova-plugin-camera/issues/665#issuecomment-752770761
Maybe we should just focus on Android on this issue. I think the issue is related to the activity being destroyed when the camera opens. (So it is probably also related to https://github.com/apache/cordova-plugin-camera/issues/696 ). My first guess is: In the onSaveInstanceState the imageFilePath is saved to the Bundle (with the IMAGE_URI key). But in the onRestoreStateForActivityResult the IMAGE_URI value is set on imageUri. (So there is a switch). When the activity has been destroyed the imageFilePath is normally set to null. ``` onSaveInstanceState if (this.imageUri != null) { state.putString(IMAGE_URI_KEY, this.imageFilePath); } ``` and ``` onRestoreStateForActivityResult if (state.containsKey(IMAGE_URI_KEY)) { //I have no idea what type of URI is being passed in this.imageUri = Uri.parse(state.getString(IMAGE_URI_KEY)); } ``` When processing the result, the plugin uses the null imageFilePath.  So maybe just storing and restoring imageUri and imageFilePath seperatly in the onSaveInstance and onRestore methods is enough. This is the stacktrace from my testing app https://github.com/PieterVanPoyer/cordova-camera-plugin-testing-app when the activity in the emulator is configured to be always destroyed when the camera opens. ``` 2020-12-30 22:42:41.774 11147-11147/com.pvpoyer.cameraplugintesting E/AndroidRuntime: FATAL EXCEPTION: main Process: com.pvpoyer.cameraplugintesting, PID: 11147 java.lang.RuntimeException: Unable to resume activity {com.pvpoyer.cameraplugintesting/com.pvpoyer.cameraplugintesting.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=Intent { }} to activity {com.pvpoyer.cameraplugintesting/com.pvpoyer.cameraplugintesting.MainActivity}: java.lang.NullPointerException: filename cannot be null at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4444) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=Intent { }} to activity {com.pvpoyer.cameraplugintesting/com.pvpoyer.cameraplugintesting.MainActivity}: java.lang.NullPointerException: filename cannot be null at android.app.ActivityThread.deliverResults(ActivityThread.java:5015) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4431) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.NullPointerException: filename cannot be null at android.media.ExifInterface.<init>(ExifInterface.java:1498) at org.apache.cordova.camera.ExifHelper.createInFile(ExifHelper.java:56) at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:481) at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:828) at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:159) at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:361) at android.app.Activity.dispatchActivityResult(Activity.java:8310) at android.app.ActivityThread.deliverResults(ActivityThread.java:5008) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4431) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
