From cd282c3d4ce6f6a61475396506c8de82ea413e87 Mon Sep 17 00:00:00 2001 From: Vlad Kozarez Date: Mon, 8 Apr 2024 17:35:21 +0100 Subject: [PATCH] AND-5647 fixed crash on NFC dialog show --- .../java/com/tangem/sdk/DefaultSessionViewDelegate.kt | 3 ++- .../src/main/java/com/tangem/sdk/ui/NfcEnableDialog.kt | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt b/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt index 1f3d164e..55a7e6ff 100644 --- a/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt +++ b/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt @@ -2,6 +2,7 @@ package com.tangem.sdk import android.app.Activity import android.os.Build +import androidx.core.app.ComponentActivity import com.tangem.Log import com.tangem.Message import com.tangem.SessionViewDelegate @@ -27,7 +28,7 @@ import com.tangem.sdk.ui.NfcSessionDialog */ class DefaultSessionViewDelegate( private val nfcManager: NfcManager, - private val activity: Activity, + private val activity: ComponentActivity, ) : SessionViewDelegate { var sdkConfig: Config = Config() diff --git a/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/NfcEnableDialog.kt b/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/NfcEnableDialog.kt index 1934e5e2..030d62fa 100644 --- a/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/NfcEnableDialog.kt +++ b/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/NfcEnableDialog.kt @@ -1,10 +1,12 @@ package com.tangem.sdk.ui -import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent import android.provider.Settings import androidx.appcompat.app.AlertDialog +import androidx.core.app.ComponentActivity +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.tangem.sdk.R import com.tangem.sdk.extensions.sdkThemeContext @@ -13,7 +15,7 @@ class NfcEnableDialog { private var dialog: AlertDialog? = null - fun show(activity: Activity) { + fun show(activity: ComponentActivity) { val builder = MaterialAlertDialogBuilder(activity.sdkThemeContext()) builder.setCancelable(false) .setIcon(R.drawable.ic_action_nfc_gray) @@ -21,7 +23,9 @@ class NfcEnableDialog { .setMessage(R.string.dialog_nfc_enable_text) .setPositiveButton(R.string.common_ok) { _, _ -> try { - activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS)) + if ((activity as? LifecycleOwner)?.lifecycle?.currentState == Lifecycle.State.STARTED) { + activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS)) + } } catch (ex: ActivityNotFoundException) { print(ex.toString()) }