summaryrefslogtreecommitdiffstats
path: root/platform/android/java/src/org/godotengine/godot/Godot.java
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2019-03-05 23:29:44 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2019-03-06 19:09:17 +0100
commit2d0d64794e17c21456f51bed5412f083398eb3a5 (patch)
treead3ef6cc53957625c544bdbb3f84331232b723e5 /platform/android/java/src/org/godotengine/godot/Godot.java
parent34a29cb0de1b34d46e2742bd1ea0a3613967e4ed (diff)
downloadredot-engine-2d0d64794e17c21456f51bed5412f083398eb3a5.tar.gz
Restart game on GL context loss on Android
Bonus: Remove useless old code about reload hooks Fixes #22955.
Diffstat (limited to 'platform/android/java/src/org/godotengine/godot/Godot.java')
-rw-r--r--platform/android/java/src/org/godotengine/godot/Godot.java28
1 files changed, 23 insertions, 5 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java
index a10d7876f4..c00199dad6 100644
--- a/platform/android/java/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/src/org/godotengine/godot/Godot.java
@@ -38,6 +38,7 @@ import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -318,6 +319,23 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
});
}
+ public void restart() {
+ // HACK:
+ //
+ // Currently it's very hard to properly deinitialize Godot on Android to restart the game
+ // from scratch. Therefore, we need to kill the whole app process and relaunch it.
+ //
+ // Restarting only the activity, wouldn't be enough unless it did proper cleanup (including
+ // releasing and reloading native libs or resetting their state somehow and clearing statics).
+ //
+ // Using instrumentation is a way of making the whole app process restart, because Android
+ // will kill any process of the same package which was already running.
+ //
+ Bundle args = new Bundle();
+ args.putParcelable("intent", mCurrentIntent);
+ startInstrumentation(new ComponentName(Godot.this, GodotInstrumentation.class), null, args);
+ }
+
public void alert(final String message, final String title) {
final Activity activity = this;
runOnUiThread(new Runnable() {
@@ -415,7 +433,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
- GodotLib.initialize(this, io.needsReloadHooks(), getAssets(), use_apk_expansion);
+ GodotLib.initialize(this, getAssets(), use_apk_expansion);
result_callback = null;
@@ -921,10 +939,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
// Audio
/**
- * The download state should trigger changes in the UI --- it may be useful
- * to show the state as being indeterminate at times. This sample can be
- * considered a guideline.
- */
+ * The download state should trigger changes in the UI --- it may be useful
+ * to show the state as being indeterminate at times. This sample can be
+ * considered a guideline.
+ */
@Override
public void onDownloadStateChanged(int newState) {
setState(newState);