Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes on Android 5.0.1 #170

Closed
kristiyandobrev opened this issue Aug 23, 2016 · 3 comments · May be fixed by #171
Closed

App crashes on Android 5.0.1 #170

kristiyandobrev opened this issue Aug 23, 2016 · 3 comments · May be fixed by #171

Comments

@kristiyandobrev
Copy link
Contributor

My ionic app recently started crashing whenever I select an image from the gallery.

Here is the console output:

08-23 12:24:05.500 7287-7287/com.test.timereg E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.test.timereg, PID: 7287
                    java.lang.RuntimeException: Unable to resume activity {com.test.timereg/com.test.timereg.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {com.test.timereg/com.test.timereg.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success(org.json.JSONArray)' on a null object reference
                        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3192)
                        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3223)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
                        at android.app.ActivityThread.access$1200(ActivityThread.java:152)
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                        at android.os.Handler.dispatchMessage(Handler.java:102)
                        at android.os.Looper.loop(Looper.java:135)
                        at android.app.ActivityThread.main(ActivityThread.java:5538)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at java.lang.reflect.Method.invoke(Method.java:372)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                    Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {com.test.timereg/com.test.timereg.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success(org.json.JSONArray)' on a null object reference
                        at android.app.ActivityThread.deliverResults(ActivityThread.java:3790)
                        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3164)
                        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3223) 
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
                        at android.app.ActivityThread.access$1200(ActivityThread.java:152) 
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) 
                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                        at android.os.Looper.loop(Looper.java:135) 
                        at android.app.ActivityThread.main(ActivityThread.java:5538) 
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at java.lang.reflect.Method.invoke(Method.java:372) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success(org.json.JSONArray)' on a null object reference
                        at com.synconset.ImagePicker.onActivityResult(ImagePicker.java:61)
                        at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:153)
                        at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:348)
                        at android.app.Activity.dispatchActivityResult(Activity.java:6238)
                        at android.app.ActivityThread.deliverResults(ActivityThread.java:3786)
                        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3164) 
                        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3223) 
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
                        at android.app.ActivityThread.access$1200(ActivityThread.java:152) 
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) 
                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                        at android.os.Looper.loop(Looper.java:135) 
                        at android.app.ActivityThread.main(ActivityThread.java:5538) 
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at java.lang.reflect.Method.invoke(Method.java:372) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
08-23 12:24:05.560 7287-7287/com.test.timereg I/Process: Sending signal. PID: 7287 SIG: 9

@danielgolub
Copy link

I think it has to do with permissions.
Because when I manually enable permission to storage on the phone settings, the app doesn't crash.
Any solution?

@kristiyandobrev
Copy link
Contributor Author

kristiyandobrev commented Aug 31, 2016

Yes, if Developer Options->Don't keep activities is enabled it will eliminate any activity when leave them. In the case of the Image Picker it will restart the activity. To solve that issue simply disable the Developer Options->Don't keep activities option.

@kuwabarahiroshi
Copy link

kuwabarahiroshi commented Aug 31, 2016

@kristiyandobrev
Android 5.0.0+ has a feature to stop background Activity when a device is running out of memory. Developer Options->Don't keep activities is the option to simulate this situation.

To avoid NullPointerException in such cases, cordova plugins should implement public void onRestoreStateForActivityResult(Bundle state, CallbackContext callbackContext).
This is documented here (http://cordova.apache.org/docs/en/dev/guide/platforms/android/plugin.html#launching-other-activities).

I made a PR #171 to fix this issue.

Other plugins such as cordova-plugin-camera had a similar issue like this (apache/cordova-plugin-camera#145)
Also see CB-9189.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants