Fix SignerActivity reopening after accepting an intent request

Two related races caused the "nothing to approve yet" flash / reopen:

1. IntentUtils.clear() in onDestroy was wiping intents added by a
   concurrently-created new SignerActivity instance. Fix: track intent
   IDs added by each MainViewModel instance (addedIntentIds) and remove
   only those in onDestroy, leaving any intents owned by the new
   instance untouched.

2. LaunchedEffect(intent) in AccountScreen received a new IntentWrapper
   reference on every recomposition (created inline), so it re-ran
   after onRemoveIntentData emptied _intents, re-adding the just-
   accepted intent before finishAndRemoveTask() could close the
   activity. Fix: wrap with remember(intent) { IntentWrapper(intent) }
   so the effect only re-runs when the actual Intent reference changes
   (i.e. a genuine new intent from onNewIntent).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
greenart7c3
2026-04-14 05:50:13 -03:00
co-authored by Claude Sonnet 4.6
parent 23a5751bd7
commit 89121d4cef
3 changed files with 18 additions and 6 deletions
@@ -146,7 +146,7 @@ class MainActivity : AppCompatActivity() {
AccountScreen(
accountStateViewModel = accountStateViewModel,
intent = IntentWrapper(intent),
intent = remember(intent) { IntentWrapper(intent) },
packageName = packageName,
appName = appName,
bunkerRequests = bunkerRequests.value,
@@ -189,8 +189,11 @@ class MainActivity : AppCompatActivity() {
}
override fun onDestroy() {
IntentUtils.clear()
val ownedIds = mainViewModel.addedIntentIds
val toRemove = IntentUtils.intents.value.filter { it.id in ownedIds }
if (toRemove.isNotEmpty()) {
IntentUtils.removeAll(toRemove)
}
super.onDestroy()
}
}
@@ -25,6 +25,11 @@ import kotlinx.coroutines.launch
class MainViewModel(val context: Context) : ViewModel() {
var navController: NavHostController? = null
// Intent IDs added by this ViewModel instance — used by onDestroy to remove only
// the intents owned by this activity, avoiding races with a new SignerActivity
// instance that may have already added its own intents.
val addedIntentIds = mutableSetOf<String>()
fun getAccount(userFromIntent: String?): String? {
val currentAccount = LocalPreferences.currentAccount(context)
try {
@@ -128,6 +133,7 @@ class MainViewModel(val context: Context) : ViewModel() {
val intentData = IntentUtils.getIntentData(context, intent, callingPackage, intent.getStringExtra("route"), acc)
if (intentData != null) {
IntentUtils.addAll(listOf(intentData))
addedIntentIds.add(intentData.id)
}
intent.getStringExtra("route")?.let { route ->
@@ -162,7 +162,7 @@ class SignerActivity : AppCompatActivity() {
AccountScreen(
accountStateViewModel = accountStateViewModel,
intent = IntentWrapper(intent),
intent = remember(intent) { IntentWrapper(intent) },
packageName = packageName,
appName = appName,
bunkerRequests = bunkerRequests.value,
@@ -207,8 +207,11 @@ class SignerActivity : AppCompatActivity() {
}
override fun onDestroy() {
IntentUtils.clear()
val ownedIds = mainViewModel.addedIntentIds
val toRemove = IntentUtils.intents.value.filter { it.id in ownedIds }
if (toRemove.isNotEmpty()) {
IntentUtils.removeAll(toRemove)
}
super.onDestroy()
}
}