From ace079d1bef5a7aea80f4275918fc1db97366d73 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 15 Apr 2026 10:16:59 -0300 Subject: [PATCH] Fixing reacting to intents after app got killed --- app/src/main/kotlin/org/fdroid/MainActivity.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/fdroid/MainActivity.kt b/app/src/main/kotlin/org/fdroid/MainActivity.kt index 24e700902..54f1550c4 100644 --- a/app/src/main/kotlin/org/fdroid/MainActivity.kt +++ b/app/src/main/kotlin/org/fdroid/MainActivity.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.content.pm.PackageManager.PERMISSION_GRANTED import android.os.Build.VERSION.SDK_INT import android.os.Bundle -import android.util.Log import android.view.WindowManager.LayoutParams.FLAG_SECURE import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge @@ -17,6 +16,7 @@ import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject import kotlinx.coroutines.launch +import mu.KotlinLogging import org.fdroid.settings.SettingsManager import org.fdroid.ui.Main import org.fdroid.ui.utils.launchSafe @@ -26,12 +26,15 @@ import org.fdroid.ui.utils.launchSafe @AndroidEntryPoint class MainActivity : AppCompatActivity() { + private val log = KotlinLogging.logger {} + val requestPermissionLauncher = registerForActivityResult(RequestPermission()) {} @Inject lateinit var settingsManager: SettingsManager override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + log.info { "onCreate($savedInstanceState)" } // observe preventScreenshots setting and react to changes lifecycleScope.launch { // this flow doesn't change when we are paused, so we keep collecting it @@ -47,6 +50,7 @@ class MainActivity : AppCompatActivity() { setContent { Main { // inform OnNewIntentListeners about the initial intent (otherwise would be missed) + log.info { "Passing initial intent: $intent" } if (intent != null) { onNewIntent(intent) // set intent to null to avoid re-processing on configuration changes @@ -63,7 +67,15 @@ class MainActivity : AppCompatActivity() { } override fun onNewIntent(intent: Intent, caller: ComponentCaller) { - Log.i("MainActivity", "onNewIntent: $intent, caller: $caller") + log.info { + val callerInfo = if (SDK_INT >= 35) caller.`package` else caller.toString() + "onNewIntent: $intent, caller: $callerInfo" + } + // if the app got killed and restarted via an intent, + // this may run before the IntentListener is attached, so it would miss this intent + if (SDK_INT >= 35) setIntent(intent, caller) else setIntent(intent) + + // calling super seems to be needed, so the IntentListener gets informed super.onNewIntent(intent, caller) } }