diff --git a/platform/android/java/editor/src/main/AndroidManifest.xml b/platform/android/java/editor/src/main/AndroidManifest.xml index 2bb6b43503f..c7b2c8ad678 100644 --- a/platform/android/java/editor/src/main/AndroidManifest.xml +++ b/platform/android/java/editor/src/main/AndroidManifest.xml @@ -35,7 +35,7 @@ @@ -53,7 +53,7 @@ android:name=".GodotEditor" android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|density|keyboard|navigation|screenLayout|uiMode" android:process=":GodotEditor" - android:launchMode="singleTask" + android:launchMode="singleInstance" android:screenOrientation="userLandscape" android:exported="false"> ? + val processNameSuffix: String + when (godotInstanceId) { GAME_ID -> { - GAME_PROCESS_NAME_SUFFIX + processNameSuffix = GAME_PROCESS_NAME_SUFFIX + targetClass = GodotGame::class.java } EDITOR_ID -> { - EDITOR_PROCESS_NAME_SUFFIX + processNameSuffix = EDITOR_PROCESS_NAME_SUFFIX + targetClass = GodotEditor::class.java } PROJECT_MANAGER_ID -> { - PROJECT_MANAGER_PROCESS_NAME_SUFFIX + processNameSuffix = PROJECT_MANAGER_PROCESS_NAME_SUFFIX + targetClass = GodotProjectManager::class.java + } + else -> { + processNameSuffix = "" + targetClass = null } - else -> "" } + + if (targetClass == javaClass) { + Log.d(TAG, "Force quitting $targetClass") + ProcessPhoenix.forceQuit(this) + return true + } + if (processNameSuffix.isBlank()) { return false } @@ -208,8 +242,16 @@ open class GodotEditor : FullScreenGodotApp() { val runningProcesses = activityManager.runningAppProcesses for (runningProcess in runningProcesses) { if (runningProcess.processName.endsWith(processNameSuffix)) { - Log.v(TAG, "Killing Godot process ${runningProcess.processName}") - Process.killProcess(runningProcess.pid) + if (targetClass == null) { + // Killing process directly + Log.v(TAG, "Killing Godot process ${runningProcess.processName}") + Process.killProcess(runningProcess.pid) + } else { + // Activity is running; sending a request for self termination. + Log.v(TAG, "Sending force quit request to $targetClass running on process ${runningProcess.processName}") + val forceQuitIntent = Intent(this, targetClass).putExtra(EXTRA_FORCE_QUIT, true) + startActivity(forceQuitIntent) + } return true } } diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.java b/platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.java index 3ee3478fcbe..b1bce45fbba 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.java @@ -90,7 +90,7 @@ public final class ProcessPhoenix extends Activity { */ public static void forceQuit(Activity activity, int pid) { Process.killProcess(pid); // Kill original main process - activity.finish(); + activity.finishAndRemoveTask(); Runtime.getRuntime().exit(0); // Kill kill kill! }