-
Notifications
You must be signed in to change notification settings - Fork 143
Android NullPointerException On Activity Destruction #91
Description
General information
- SDK/Library version: 2.1.0
- Platforms: Android
- Device OS Version and Device: Android 7 on Nexus 5X
Issue description
The Android OS will destroy activities when the user navigates away from them if the device is low on memory.
If the device is in this mode, when the user navigates to the camera activity from their app, when an attempt to navigate back to the app is made, the app crashes with the following exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success(org.json.JSONObject)' on a null object reference
io.card.cordova.sdk.CardIOCordovaPlugin.onActivityResult (CardIOCordovaPlugin.java:98)
org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:159)
org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:359)
android.app.Activity.dispatchActivityResult (Activity.java:7539)
android.app.ActivityThread.deliverResults (ActivityThread.java:4485)
android.app.ActivityThread.performResumeActivity (ActivityThread.java:3760)
android.app.ActivityThread.handleResumeActivity (ActivityThread.java:3828)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3036)
android.app.ActivityThread.-wrap11 ()
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6938)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
The standard way to fix this is to override onRestoreStateForActivityResult in the Android Activity.
Steps to reproduce:
- Open Developer Options on Android device
- Enable the Don't keep activities setting
- Click button in your app to initiate the camera intent
- Take image of credit card
- When the system attempt to navigate back to the app, a crash occurs