card-io / card.io-Cordova-Plugin

card.io Cordova Plugin
Other
174 stars 146 forks source link

Android NullPointerException On Activity Destruction #91

Open hvaughan3 opened 6 years ago

hvaughan3 commented 6 years ago

General information

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:

  1. Open Developer Options on Android device
  2. Enable the Don't keep activities setting
  3. Click button in your app to initiate the camera intent
  4. Take image of credit card
  5. When the system attempt to navigate back to the app, a crash occurs