|
@@ -32,11 +32,12 @@ package org.godotengine.godot;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
-import android.view.KeyEvent;
|
|
|
+import android.util.Log;
|
|
|
|
|
|
import androidx.annotation.CallSuper;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
+import androidx.fragment.app.Fragment;
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
|
|
|
/**
|
|
@@ -46,6 +47,8 @@ import androidx.fragment.app.FragmentActivity;
|
|
|
* within an Android app.
|
|
|
*/
|
|
|
public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost {
|
|
|
+ private static final String TAG = FullScreenGodotApp.class.getSimpleName();
|
|
|
+
|
|
|
@Nullable
|
|
|
private Godot godotFragment;
|
|
|
|
|
@@ -53,12 +56,33 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.godot_app_layout);
|
|
|
- godotFragment = initGodotInstance();
|
|
|
- if (godotFragment == null) {
|
|
|
- throw new IllegalStateException("Godot instance must be non-null.");
|
|
|
+
|
|
|
+ Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.godot_fragment_container);
|
|
|
+ if (currentFragment instanceof Godot) {
|
|
|
+ Log.v(TAG, "Reusing existing Godot fragment instance.");
|
|
|
+ godotFragment = (Godot)currentFragment;
|
|
|
+ } else {
|
|
|
+ Log.v(TAG, "Creating new Godot fragment instance.");
|
|
|
+ godotFragment = initGodotInstance();
|
|
|
+ if (godotFragment == null) {
|
|
|
+ throw new IllegalStateException("Godot instance must be non-null.");
|
|
|
+ }
|
|
|
+
|
|
|
+ getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss();
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ onGodotForceQuit(godotFragment);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public final void onGodotForceQuit(Godot instance) {
|
|
|
+ if (instance == godotFragment) {
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|