diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt index 8da1c7d7227..0fcf8944426 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt @@ -21,6 +21,7 @@ package com.wire.android.ui import android.app.Activity import android.content.Intent import android.net.Uri +import android.os.Build import android.os.Bundle import android.view.WindowManager import android.widget.Toast @@ -65,8 +66,8 @@ import com.wire.android.navigation.NavigationGraph import com.wire.android.navigation.navigateToItem import com.wire.android.navigation.rememberNavigator import com.wire.android.ui.calling.getIncomingCallIntent -import com.wire.android.ui.calling.ongoing.getOngoingCallIntent import com.wire.android.ui.calling.getOutgoingCallIntent +import com.wire.android.ui.calling.ongoing.getOngoingCallIntent import com.wire.android.ui.common.snackbar.LocalSnackbarHostState import com.wire.android.ui.common.topappbar.CommonTopAppBar import com.wire.android.ui.common.topappbar.CommonTopAppBarViewModel @@ -514,17 +515,26 @@ class WireActivity : AppCompatActivity() { override fun onSaveInstanceState(outState: Bundle) { outState.putBoolean(HANDLED_DEEPLINK_FLAG, true) + outState.putParcelable(ORIGINAL_SAVED_INTENT_FLAG, intent) super.onSaveInstanceState(outState) } + override fun onRestoreInstanceState(savedInstanceState: Bundle) { + super.onRestoreInstanceState(savedInstanceState) + savedInstanceState.getOriginalIntent()?.let { + this.intent = it + } + } + @Suppress("ComplexCondition") private fun handleDeepLink( intent: Intent?, savedInstanceState: Bundle? = null ) { + val originalIntent = savedInstanceState.getOriginalIntent() if (intent == null || intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0 - || savedInstanceState?.getBoolean(HANDLED_DEEPLINK_FLAG, false) == true + || originalIntent == intent // This is the case when the activity is recreated and already handled || intent.getBooleanExtra(HANDLED_DEEPLINK_FLAG, false) ) { return @@ -561,6 +571,15 @@ class WireActivity : AppCompatActivity() { } } + private fun Bundle?.getOriginalIntent(): Intent? { + return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + @Suppress("DEPRECATION") // API 33 + this?.getParcelable(ORIGINAL_SAVED_INTENT_FLAG) + } else { + this?.getParcelable(ORIGINAL_SAVED_INTENT_FLAG, Intent::class.java) + } + } + private fun handleDeepLinkResult(result: DeepLinkResult) { val navigate: (NavigationCommand) -> Unit = { lifecycleScope.launch { navigationCommands.emit(it) } } when (result) { @@ -598,6 +617,7 @@ class WireActivity : AppCompatActivity() { companion object { private const val HANDLED_DEEPLINK_FLAG = "deeplink_handled_flag_key" + private const val ORIGINAL_SAVED_INTENT_FLAG = "original_saved_intent" private const val TAG = "WireActivity" } }