1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

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/78129
This commit is contained in:
Fredia Huya-Kouadio
2023-06-15 21:11:40 -07:00
parent c0d8d91b15
commit 0664f5ec3b
3 changed files with 35 additions and 23 deletions

View File

@@ -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) {