diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 368acecc3d0..ac903cab5d0 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -60,7 +60,6 @@ import android.content.pm.ConfigurationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; -import android.graphics.Point; import android.graphics.Rect; import android.hardware.Sensor; import android.hardware.SensorEvent; @@ -86,7 +85,6 @@ import android.view.Window; import android.view.WindowInsets; import android.view.WindowInsetsAnimation; import android.view.WindowManager; -import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ProgressBar; @@ -97,9 +95,6 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; -import androidx.core.view.OnApplyWindowInsetsListener; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import com.google.android.vending.expansion.downloader.DownloadProgressInfo; @@ -894,7 +889,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } return; } - mView.onPause(); + mView.onActivityPaused(); mSensorManager.unregisterListener(this); @@ -906,6 +901,18 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } } + @Override + public void onStop() { + super.onStop(); + if (!godot_initialized) { + if (null != mDownloaderClientStub) { + mDownloaderClientStub.disconnect(getActivity()); + } + return; + } + mView.onActivityStopped(); + } + public boolean hasClipboard() { return mClipboard.hasPrimaryClip(); } @@ -925,6 +932,19 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC mClipboard.setPrimaryClip(clip); } + @Override + public void onStart() { + super.onStart(); + if (!godot_initialized) { + if (null != mDownloaderClientStub) { + mDownloaderClientStub.connect(getActivity()); + } + return; + } + + mView.onActivityStarted(); + } + @Override public void onResume() { super.onResume(); @@ -936,7 +956,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC return; } - mView.onResume(); + mView.onActivityResumed(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME); diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotView.java index ce5e3aeef22..a54261279fa 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotView.java @@ -302,10 +302,11 @@ public class GodotView extends GLSurfaceView { return inputHandler; } - @Override - public void onResume() { - super.onResume(); + void onActivityStarted() { + resumeGLThread(); + } + void onActivityResumed() { queueEvent(() -> { // Resume the renderer godotRenderer.onActivityResumed(); @@ -313,14 +314,15 @@ public class GodotView extends GLSurfaceView { }); } - @Override - public void onPause() { - super.onPause(); - + void onActivityPaused() { queueEvent(() -> { GodotLib.focusout(); // Pause the renderer godotRenderer.onActivityPaused(); }); } + + void onActivityStopped() { + pauseGLThread(); + } } diff --git a/platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView.java b/platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView.java index 8449c08b88d..98384ba5db6 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView.java @@ -122,8 +122,8 @@ import javax.microedition.khronos.opengles.GL10; *

*

Activity Life-cycle

* A GLSurfaceView must be notified when to pause and resume rendering. GLSurfaceView clients - * are required to call {@link #onPause()} when the activity stops and - * {@link #onResume()} when the activity starts. These calls allow GLSurfaceView to + * are required to call {@link #pauseGLThread()} when the activity stops and + * {@link #resumeGLThread()} when the activity starts. These calls allow GLSurfaceView to * pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate * the OpenGL display. *

@@ -339,8 +339,8 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback * setRenderer is called: *