Add parameters for the Godot Activity starting intent to allow restarting or force-quitting the engine
Follow-up code cleanup for https://github.com/godotengine/godot/pull/78130
This commit is contained in:
parent
9ba9a41766
commit
5cf0ba88e3
@ -66,7 +66,7 @@
|
|||||||
android:name=".GodotApp"
|
android:name=".GodotApp"
|
||||||
android:label="@string/godot_project_name_string"
|
android:label="@string/godot_project_name_string"
|
||||||
android:theme="@style/GodotAppSplashTheme"
|
android:theme="@style/GodotAppSplashTheme"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleInstance"
|
||||||
android:excludeFromRecents="false"
|
android:excludeFromRecents="false"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:screenOrientation="landscape"
|
android:screenOrientation="landscape"
|
||||||
|
@ -62,7 +62,6 @@ open class GodotEditor : FullScreenGodotApp() {
|
|||||||
|
|
||||||
private const val WAIT_FOR_DEBUGGER = false
|
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 EXTRA_COMMAND_LINE_PARAMS = "command_line_params"
|
||||||
|
|
||||||
private const val EDITOR_ID = 777
|
private const val EDITOR_ID = 777
|
||||||
@ -96,7 +95,9 @@ open class GodotEditor : FullScreenGodotApp() {
|
|||||||
// requested on demand based on use-cases.
|
// requested on demand based on use-cases.
|
||||||
PermissionsUtil.requestManifestPermissions(this, setOf(Manifest.permission.RECORD_AUDIO))
|
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) {
|
if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) {
|
||||||
Debug.waitForDebugger()
|
Debug.waitForDebugger()
|
||||||
@ -105,25 +106,6 @@ open class GodotEditor : FullScreenGodotApp() {
|
|||||||
super.onCreate(savedInstanceState)
|
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() {
|
override fun onGodotSetupCompleted() {
|
||||||
super.onGodotSetupCompleted()
|
super.onGodotSetupCompleted()
|
||||||
val longPressEnabled = enableLongPressGestures()
|
val longPressEnabled = enableLongPressGestures()
|
||||||
@ -154,7 +136,7 @@ open class GodotEditor : FullScreenGodotApp() {
|
|||||||
private fun updateCommandLineParams(args: Array<String>?) {
|
private fun updateCommandLineParams(args: Array<String>?) {
|
||||||
// Update the list of command line params with the new args
|
// Update the list of command line params with the new args
|
||||||
commandLineParams.clear()
|
commandLineParams.clear()
|
||||||
if (args != null && args.isNotEmpty()) {
|
if (!args.isNullOrEmpty()) {
|
||||||
commandLineParams.addAll(listOf(*args))
|
commandLineParams.addAll(listOf(*args))
|
||||||
}
|
}
|
||||||
if (BuildConfig.BUILD_TYPE == "dev") {
|
if (BuildConfig.BUILD_TYPE == "dev") {
|
||||||
@ -201,6 +183,7 @@ open class GodotEditor : FullScreenGodotApp() {
|
|||||||
ProcessPhoenix.triggerRebirth(this, newInstance)
|
ProcessPhoenix.triggerRebirth(this, newInstance)
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Starting $targetClass with parameters ${args.contentToString()}")
|
Log.d(TAG, "Starting $targetClass with parameters ${args.contentToString()}")
|
||||||
|
newInstance.putExtra(EXTRA_NEW_LAUNCH, true)
|
||||||
startActivity(newInstance)
|
startActivity(newInstance)
|
||||||
}
|
}
|
||||||
return instanceId
|
return instanceId
|
||||||
|
@ -51,6 +51,9 @@ import androidx.fragment.app.FragmentActivity;
|
|||||||
public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost {
|
public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost {
|
||||||
private static final String TAG = FullScreenGodotApp.class.getSimpleName();
|
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
|
@Nullable
|
||||||
private Godot godotFragment;
|
private Godot godotFragment;
|
||||||
|
|
||||||
@ -59,6 +62,8 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.godot_app_layout);
|
setContentView(R.layout.godot_app_layout);
|
||||||
|
|
||||||
|
handleStartIntent(getIntent(), true);
|
||||||
|
|
||||||
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.godot_fragment_container);
|
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.godot_fragment_container);
|
||||||
if (currentFragment instanceof Godot) {
|
if (currentFragment instanceof Godot) {
|
||||||
Log.v(TAG, "Reusing existing Godot fragment instance.");
|
Log.v(TAG, "Reusing existing Godot fragment instance.");
|
||||||
@ -109,11 +114,35 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God
|
|||||||
@Override
|
@Override
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
setIntent(intent);
|
||||||
|
|
||||||
|
handleStartIntent(intent, false);
|
||||||
|
|
||||||
if (godotFragment != null) {
|
if (godotFragment != null) {
|
||||||
godotFragment.onNewIntent(intent);
|
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
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user