mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-10-02 00:56:23 -04:00
Fixing reacting to intents after app got killed
This commit is contained in:
1 file changed
+14
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user