Skip to content

Commit bd56674

Browse files
authored
Add activity state detection to prevent parameter conflicts when resuming from home screen after external game launch (#18231)
* Simplified onNewIntent content detection logic and added activity state tracking * Added activity state detection to prevent parameter conflicts when resuming from home screen
1 parent 1834795 commit bd56674

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

pkg/android/phoenix/src/com/retroarch/browser/mainmenu/MainMenuActivity.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,30 @@ public void onClick(DialogInterface dialog, int which)
115115

116116
public void finalStartup()
117117
{
118-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
119118
Intent retro = new Intent(this, RetroActivityFuture.class);
120-
121-
retro.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
122-
123-
startRetroActivity(
124-
retro,
125-
null,
126-
prefs.getString("libretro_path", getApplicationInfo().dataDir + "/cores/"),
127-
UserPreferences.getDefaultConfigPath(this),
128-
Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
129-
getApplicationInfo().dataDir,
130-
getApplicationInfo().sourceDir);
119+
120+
if (RetroActivityFuture.isRunning) {
121+
// RetroActivity is already running - just bring it to front
122+
retro.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
123+
} else {
124+
// RetroActivity not running - full setup with parameters
125+
retro.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
126+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
127+
128+
startRetroActivity(
129+
retro,
130+
null,
131+
prefs.getString("libretro_path", getApplicationInfo().dataDir + "/cores/"),
132+
UserPreferences.getDefaultConfigPath(this),
133+
Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
134+
getApplicationInfo().dataDir,
135+
getApplicationInfo().sourceDir);
136+
}
137+
131138
startActivity(retro);
132139
finish();
133140
}
141+
134142

135143
@Override
136144
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)

pkg/android/phoenix/src/com/retroarch/browser/retroactivity/RetroActivityFuture.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
public final class RetroActivityFuture extends RetroActivityCamera {
2121

22+
// Tracks activity lifecycle state for MainMenuActivity resume detection
23+
public static volatile boolean isRunning = false;
24+
2225
// If set to true then RetroArch will completely exit when it loses focus
2326
private boolean quitfocus = false;
2427

@@ -55,7 +58,8 @@ public void handleMessage(Message msg) {
5558
@Override
5659
public void onCreate(Bundle savedInstanceState) {
5760
super.onCreate(savedInstanceState);
58-
61+
62+
isRunning = true;
5963
mDecorView = getWindow().getDecorView();
6064

6165
// If QUITFOCUS parameter is provided then enable that Retroarch quits when focus is lost
@@ -66,7 +70,7 @@ public void onCreate(Bundle savedInstanceState) {
6670
public void onNewIntent(Intent intent) {
6771
super.onNewIntent(intent);
6872

69-
// Check if this intent contains game launch parameters
73+
// Extract game parameters from new intent
7074
String newRom = intent.getStringExtra("ROM");
7175
String newCore = intent.getStringExtra("LIBRETRO");
7276

@@ -75,17 +79,11 @@ public void onNewIntent(Intent intent) {
7579
String currentRom = currentIntent != null ? currentIntent.getStringExtra("ROM") : null;
7680
String currentCore = currentIntent != null ? currentIntent.getStringExtra("LIBRETRO") : null;
7781

78-
// Check if we're trying to launch different content
79-
boolean isDifferentContent = false;
80-
if (newRom != null && !newRom.equals(currentRom)) {
81-
isDifferentContent = true;
82-
}
83-
if (newCore != null && !newCore.equals(currentCore)) {
84-
isDifferentContent = true;
85-
}
8682

87-
if (isDifferentContent) {
88-
// Exit cleanly and let the system restart us with new content
83+
// Check if we're trying to launch different content
84+
if ((newRom != null && !newRom.equals(currentRom)) ||
85+
(newCore != null && !newCore.equals(currentCore))) {
86+
// Different game content - exit cleanly and let launcher restart us
8987
finish();
9088
System.exit(0);
9189
} else {
@@ -94,7 +92,6 @@ public void onNewIntent(Intent intent) {
9492
}
9593
}
9694

97-
9895
@Override
9996
public void onResume() {
10097
super.onResume();
@@ -134,6 +131,12 @@ public void onStop() {
134131
if (quitfocus) System.exit(0);
135132
}
136133

134+
@Override
135+
public void onDestroy() {
136+
super.onDestroy();
137+
isRunning = false;
138+
}
139+
137140
@Override
138141
public void onWindowFocusChanged(boolean hasFocus) {
139142
super.onWindowFocusChanged(hasFocus);

0 commit comments

Comments
 (0)