Delegate handling and implementation of the restart functionality to the Godot host.
This commit is contained in:
parent
01675eb75a
commit
f4222733ca
3 changed files with 29 additions and 16 deletions
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
package org.godotengine.godot;
|
package org.godotengine.godot;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -85,6 +86,26 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onGodotRestartRequested(Godot instance) {
|
||||||
|
if (instance == godotFragment) {
|
||||||
|
// 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", getIntent());
|
||||||
|
startInstrumentation(new ComponentName(this, GodotInstrumentation.class), null, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
|
@ -331,22 +331,8 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restart() {
|
public void restart() {
|
||||||
// HACK:
|
if (godotHost != null) {
|
||||||
//
|
godotHost.onGodotRestartRequested(this);
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putParcelable("intent", mCurrentIntent);
|
|
||||||
activity.startInstrumentation(new ComponentName(activity, GodotInstrumentation.class), null, args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,4 +58,10 @@ public interface GodotHost {
|
||||||
* Invoked on the UI thread as the last step of the Godot instance clean up phase.
|
* Invoked on the UI thread as the last step of the Godot instance clean up phase.
|
||||||
*/
|
*/
|
||||||
default void onGodotForceQuit(Godot instance) {}
|
default void onGodotForceQuit(Godot instance) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked on the GL thread when the Godot instance wants to be restarted. It's up to the host
|
||||||
|
* to perform the appropriate action(s).
|
||||||
|
*/
|
||||||
|
default void onGodotRestartRequested(Godot instance) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue