1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-16 14:00:40 +00:00

Handling BackPress event [Android]

This commit is contained in:
Ramesh Ravone
2017-10-03 11:33:37 +05:30
parent 0f9e1b5f0c
commit 2ba23c8ae7
2 changed files with 13 additions and 2 deletions

View File

@@ -191,6 +191,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
protected void onMainPause() {} protected void onMainPause() {}
protected void onMainResume() {} protected void onMainResume() {}
protected void onMainDestroy() {} protected void onMainDestroy() {}
protected boolean onMainBackPressed() { return false; }
protected void onGLDrawFrame(GL10 gl) {} protected void onGLDrawFrame(GL10 gl) {}
protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
@@ -727,10 +728,20 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
*/ */
@Override public void onBackPressed() { @Override public void onBackPressed() {
boolean shouldQuit = true;
for(int i=0;i<singleton_count;i++) {
if (singletons[i].onMainBackPressed()) {
shouldQuit = false;
}
}
System.out.printf("** BACK REQUEST!\n"); System.out.printf("** BACK REQUEST!\n");
if (shouldQuit) {
GodotLib.quit(); GodotLib.quit();
} }
}
public void forceQuit() { public void forceQuit() {

View File

@@ -264,7 +264,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
GodotLib.quit(); activity.onBackPressed();
// press 'back' button should not terminate program // press 'back' button should not terminate program
// normal handle 'back' event in game logic // normal handle 'back' event in game logic
return true; return true;