Fixing reacting to intents after app got killed

This commit is contained in:
Torsten Grote committed 2026-04-28 09:11:12 -03:00
1 parent 99bd047022
commit ace079d1be
1 file changed
+14 -2
+14 -2
View File
@@ -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)
}
}