Forráskód Böngészése

Merge pull request #78306 from m4gr3d/cleanup_launch_flow_main

Add parameters for the Godot Activity starting intent to allow restarting or force-quitting the engine
Rémi Verschelde 2 éve
szülő
commit
6d1ca52792

+ 1 - 1
platform/android/java/app/AndroidManifest.xml

@@ -35,7 +35,7 @@
             android:name=".GodotApp"
             android:label="@string/godot_project_name_string"
             android:theme="@style/GodotAppSplashTheme"
-            android:launchMode="singleTask"
+            android:launchMode="singleInstance"
             android:excludeFromRecents="false"
             android:exported="true"
             android:screenOrientation="landscape"

+ 5 - 22
platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt

@@ -62,7 +62,6 @@ open class GodotEditor : FullScreenGodotApp() {
 
 		private const val WAIT_FOR_DEBUGGER = false
 
-		private const val EXTRA_FORCE_QUIT = "force_quit_requested"
 		private const val EXTRA_COMMAND_LINE_PARAMS = "command_line_params"
 
 		private const val EDITOR_ID = 777
@@ -96,7 +95,9 @@ open class GodotEditor : FullScreenGodotApp() {
 		// requested on demand based on use-cases.
 		PermissionsUtil.requestManifestPermissions(this, setOf(Manifest.permission.RECORD_AUDIO))
 
-		handleIntentParams(intent)
+		val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
+		Log.d(TAG, "Received parameters ${params.contentToString()}")
+		updateCommandLineParams(params)
 
 		if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) {
 			Debug.waitForDebugger()
@@ -105,25 +106,6 @@ open class GodotEditor : FullScreenGodotApp() {
 		super.onCreate(savedInstanceState)
 	}
 
-	override fun onNewIntent(newIntent: Intent) {
-		intent = newIntent
-		handleIntentParams(newIntent)
-		super.onNewIntent(newIntent)
-	}
-
-	private fun handleIntentParams(receivedIntent: Intent) {
-		val forceQuitRequested = receivedIntent.getBooleanExtra(EXTRA_FORCE_QUIT, false)
-		if (forceQuitRequested) {
-			Log.d(TAG, "Force quit requested, terminating..")
-			ProcessPhoenix.forceQuit(this)
-			return
-		}
-
-		val params = receivedIntent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
-		Log.d(TAG, "Received parameters ${params.contentToString()}")
-		updateCommandLineParams(params)
-	}
-
 	override fun onGodotSetupCompleted() {
 		super.onGodotSetupCompleted()
 		val longPressEnabled = enableLongPressGestures()
@@ -154,7 +136,7 @@ open class GodotEditor : FullScreenGodotApp() {
 	private fun updateCommandLineParams(args: Array<String>?) {
 		// Update the list of command line params with the new args
 		commandLineParams.clear()
-		if (args != null && args.isNotEmpty()) {
+		if (!args.isNullOrEmpty()) {
 			commandLineParams.addAll(listOf(*args))
 		}
 		if (BuildConfig.BUILD_TYPE == "dev") {
@@ -201,6 +183,7 @@ open class GodotEditor : FullScreenGodotApp() {
 			ProcessPhoenix.triggerRebirth(this, newInstance)
 		} else {
 			Log.d(TAG, "Starting $targetClass with parameters ${args.contentToString()}")
+			newInstance.putExtra(EXTRA_NEW_LAUNCH, true)
 			startActivity(newInstance)
 		}
 		return instanceId

+ 29 - 0
platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java

@@ -51,6 +51,9 @@ import androidx.fragment.app.FragmentActivity;
 public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost {
 	private static final String TAG = FullScreenGodotApp.class.getSimpleName();
 
+	protected static final String EXTRA_FORCE_QUIT = "force_quit_requested";
+	protected static final String EXTRA_NEW_LAUNCH = "new_launch_requested";
+
 	@Nullable
 	private Godot godotFragment;
 
@@ -59,6 +62,8 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.godot_app_layout);
 
+		handleStartIntent(getIntent(), true);
+
 		Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.godot_fragment_container);
 		if (currentFragment instanceof Godot) {
 			Log.v(TAG, "Reusing existing Godot fragment instance.");
@@ -109,11 +114,35 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God
 	@Override
 	public void onNewIntent(Intent intent) {
 		super.onNewIntent(intent);
+		setIntent(intent);
+
+		handleStartIntent(intent, false);
+
 		if (godotFragment != null) {
 			godotFragment.onNewIntent(intent);
 		}
 	}
 
+	private void handleStartIntent(Intent intent, boolean newLaunch) {
+		boolean forceQuitRequested = intent.getBooleanExtra(EXTRA_FORCE_QUIT, false);
+		if (forceQuitRequested) {
+			Log.d(TAG, "Force quit requested, terminating..");
+			ProcessPhoenix.forceQuit(this);
+			return;
+		}
+
+		if (!newLaunch) {
+			boolean newLaunchRequested = intent.getBooleanExtra(EXTRA_NEW_LAUNCH, false);
+			if (newLaunchRequested) {
+				Log.d(TAG, "New launch requested, restarting..");
+
+				Intent restartIntent = new Intent(intent).putExtra(EXTRA_NEW_LAUNCH, false);
+				ProcessPhoenix.triggerRebirth(this, restartIntent);
+				return;
+			}
+		}
+	}
+
 	@CallSuper
 	@Override
 	public void onActivityResult(int requestCode, int resultCode, Intent data) {