app: fix navigation when flashing modules

When launching a flash intent using FLAG_ACTIVITY_CLEAR_TOP, Android
recreates MainActivity if singleTop or singleTask is not set, causing
the app to briefly display the home screen before showing the flash
screen.

Set MainActivity to singleTask, add FLAG_ACTIVITY_SINGLE_TOP to flash
intents, and default cold-start flash zip intents to the modules tab.

Assisted-by: Gemini 3.7 Flash
This commit is contained in:
topjohnwu
2026-08-31 23:46:10 -07:00
parent 3e6e4326b1
commit 7847ab6de8
4 changed files with 8 additions and 6 deletions
+1
View File
@@ -6,6 +6,7 @@
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -228,10 +228,11 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
}
private fun getInitialTab(intent: Intent?): Int {
val section = if (intent?.action == Intent.ACTION_APPLICATION_PREFERENCES) {
Const.Nav.SETTINGS
} else {
intent?.getStringExtra(Const.Key.OPEN_SECTION)
val section = when {
intent?.action == Intent.ACTION_APPLICATION_PREFERENCES -> Const.Nav.SETTINGS
intent?.action == FlashUtils.INTENT_FLASH &&
intent.getStringExtra(FlashUtils.EXTRA_FLASH_ACTION) == Const.Value.FLASH_ZIP -> Const.Nav.MODULES
else -> intent?.getStringExtra(Const.Key.OPEN_SECTION)
}
return when (section) {
Const.Nav.SUPERUSER -> Tab.SUPERUSER.ordinal
@@ -20,7 +20,7 @@ object FlashUtils {
action = INTENT_FLASH
putExtra(EXTRA_FLASH_ACTION, Const.Value.FLASH_ZIP)
putExtra(EXTRA_FLASH_URI, file.toString())
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
return PendingIntent.getActivity(
context, file.hashCode(), intent,
@@ -147,7 +147,7 @@ fun HomeScreen(
val intent = Intent(context, context.javaClass).apply {
action = FlashUtils.INTENT_FLASH
putExtra(FlashUtils.EXTRA_FLASH_ACTION, Const.Value.UNINSTALL)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
context.startActivity(intent)
},