This commit is contained in:
bug 2026-03-21 10:40:47 -07:00 committed by GitHub
commit adc10f303c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 59 additions and 4 deletions

View File

@ -119,7 +119,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
}
override fun onDetach() {
NativeLibrary.clearEmulationActivity()
// Don't clear the reference if a newer EmulationActivity already took over
if (NativeLibrary.getEmulationActivity() === emulationActivity) {
NativeLibrary.clearEmulationActivity()
}
super.onDetach()
}
@ -154,7 +157,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
override fun surfaceDestroyed(holder: SurfaceHolder) {
Log.debug("[EmulationFragment] Surface destroyed.")
NativeLibrary.SurfaceDestroyed()
// Don't tear down the surface if a newer EmulationActivity already took over
if (NativeLibrary.getEmulationActivity() === emulationActivity) {
NativeLibrary.SurfaceDestroyed()
}
runWhenSurfaceIsValid = true
}

View File

@ -2,6 +2,7 @@
package org.dolphinemu.dolphinemu.ui.main
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.Menu
@ -90,6 +91,12 @@ class MainActivity : AppCompatActivity(), MainView, OnRefreshListener, ThemeProv
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
StartupHandler.HandleInit(this)
}
override fun onResume() {
ThemeHelper.setCorrectTheme(this)

View File

@ -66,6 +66,12 @@ class TvMainActivity : FragmentActivity(), MainView, OnRefreshListener {
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
StartupHandler.HandleInit(this)
}
override fun onResume() {
super.onResume()
if (DirectoryInitialization.shouldStart(this)) {

View File

@ -9,7 +9,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LifecycleOwner;
@ -38,11 +41,44 @@ public final class StartupHandler
String[] gamesToLaunch = getGamesFromIntent(parent.getIntent());
if (gamesToLaunch != null && gamesToLaunch.length > 0)
{
// Start the emulation activity, send the ISO passed in and finish the main activity
EmulationActivity.launch(parent, gamesToLaunch, false, true);
// If a previous session is still running, stop it and wait for it to finish
// before launching the new game. StopEmulation is async, so launching immediately
// would race with the old emulation thread's cleanup.
if (!NativeLibrary.IsUninitialized())
{
NativeLibrary.StopEmulation();
waitForStopThenLaunch(parent, gamesToLaunch);
}
else
{
EmulationActivity.stopIgnoringLaunchRequests();
EmulationActivity.launch(parent, gamesToLaunch, false, true);
}
}
}
private static void waitForStopThenLaunch(FragmentActivity parent, String[] gamesToLaunch)
{
Handler handler = new Handler(Looper.getMainLooper());
final long deadline = System.currentTimeMillis() + 5000;
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (NativeLibrary.IsUninitialized() || System.currentTimeMillis() >= deadline)
{
EmulationActivity.stopIgnoringLaunchRequests();
EmulationActivity.launch(parent, gamesToLaunch, false, true);
}
else
{
handler.postDelayed(this, 100);
}
}
}, 100);
}
private static String[] getGamesFromIntent(Intent intent)
{
// Priority order when looking for game paths in an intent: