diff --git a/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScanPlugin.kt b/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScanPlugin.kt index bdb5adf5..e3a58f68 100644 --- a/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScanPlugin.kt +++ b/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScanPlugin.kt @@ -16,9 +16,11 @@ class BarcodeScanPlugin(val activity: Activity): MethodCallHandler, @JvmStatic fun registerWith(registrar: Registrar): Unit { val channel = MethodChannel(registrar.messenger(), "com.apptreesoftware.barcode_scan") - val plugin = BarcodeScanPlugin(registrar.activity()) - channel.setMethodCallHandler(plugin) - registrar.addActivityResultListener(plugin) + if (registrar.activity() != null) { + val plugin = BarcodeScanPlugin(registrar.activity()) + channel.setMethodCallHandler(plugin) + registrar.addActivityResultListener(plugin) + } } }