@@ -298,21 +298,23 @@ private void printConfig(EGL10 egl, EGLDisplay display,
298298 private EGLConfig mEglConfig = null ;
299299
300300 // The user program is not participating in the pause protocol.
301- public final int PAUSE_NOT_PARTICIPATING = 0 ;
301+ static int PAUSE_NOT_PARTICIPATING = 0 ;
302302
303303 // A pause has not been requested by the OS.
304- public final int PAUSE_NONE = 1 ;
304+ static int PAUSE_NONE = 1 ;
305305
306306 // A pause has been requested by Android, but the user program has
307307 // not bothered responding yet.
308- public final int PAUSE_REQUEST = 2 ;
308+ static int PAUSE_REQUEST = 2 ;
309309
310310 // The user program is waiting in waitForResume.
311- public final int PAUSE_WAIT_FOR_RESUME = 3 ;
311+ static int PAUSE_WAIT_FOR_RESUME = 3 ;
312312
313- // This stores the state of the pause system.
314- private int mPause = PAUSE_NOT_PARTICIPATING ;
313+ static int PAUSE_STOP_REQUEST = 4 ;
314+ static int PAUSE_STOP_ACK = 5 ;
315315
316+ // This stores the state of the pause system.
317+ static int mPause = PAUSE_NOT_PARTICIPATING ;
316318
317319 private PowerManager .WakeLock wakeLock ;
318320
@@ -330,9 +332,14 @@ private void printConfig(EGL10 egl, EGLDisplay display,
330332 // The resource manager we use.
331333 ResourceManager mResourceManager ;
332334
335+ // Our own view
336+ static SDLSurfaceView instance = null ;
337+
333338 public SDLSurfaceView (Activity act , String argument ) {
334339 super (act );
335340
341+ SDLSurfaceView .instance = this ;
342+
336343 mActivity = act ;
337344 mResourceManager = new ResourceManager (act );
338345
@@ -435,18 +442,62 @@ public void onResume() {
435442 wakeLock .acquire ();
436443 }
437444
445+ public void onDestroy () {
446+ Log .w (TAG , "onDestroy() called" );
447+ synchronized (this ) {
448+ this .notifyAll ();
449+
450+ if ( mPause == PAUSE_STOP_ACK ) {
451+ Log .d (TAG , "onDestroy() app already leaved." );
452+ return ;
453+ }
454+
455+ // application didn't leave, give 10s before closing.
456+ // hopefully, this could be enough for launching the on_stop() trigger within the app.
457+ mPause = PAUSE_STOP_REQUEST ;
458+ int i = 50 ;
459+
460+ Log .d (TAG , "onDestroy() stop requested, wait for an event from the app" );
461+ for (; i >= 0 && mPause == PAUSE_STOP_REQUEST ; i --) {
462+ try {
463+ this .wait (200 );
464+ } catch (InterruptedException e ) {
465+ break ;
466+ }
467+ }
468+ Log .d (TAG , "onDestroy() stop finished waiting." );
469+ }
470+ }
471+
472+ static int checkStop () {
473+ if (mPause == PAUSE_STOP_REQUEST )
474+ return 1 ;
475+ return 0 ;
476+ }
477+
478+ static void ackStop () {
479+ Log .d (TAG , "ackStop() notify" );
480+ synchronized (instance ) {
481+ mPause = PAUSE_STOP_ACK ;
482+ instance .notifyAll ();
483+ }
484+ }
485+
486+
438487 /**
439488 * This method is part of the SurfaceHolder.Callback interface, and is
440489 * not normally called or subclassed by clients of GLSurfaceView.
441490 */
442491 public void surfaceCreated (SurfaceHolder holder ) {
492+ Log .i (TAG , "surfaceCreated() is not handled :|" );
443493 }
444494
445495 /**
446496 * This method is part of the SurfaceHolder.Callback interface, and is
447497 * not normally called or subclassed by clients of GLSurfaceView.
448498 */
449499 public void surfaceDestroyed (SurfaceHolder holder ) {
500+ Log .i (TAG , "surfaceDestroyed() is not handled :|" );
450501 }
451502
452503 /**
@@ -556,10 +607,12 @@ public void run() {
556607 nativeSetEnv ("PYTHONOPTIMIZE" , "2" );
557608 nativeSetEnv ("PYTHONHOME" , mFilesDirectory );
558609 nativeSetEnv ("PYTHONPATH" , mArgument + ":" + mFilesDirectory + "/lib" );
559- //nativeSetMouseUsed();
560610 nativeSetMultitouchUsed ();
561611 nativeInit ();
562612
613+ mPause = PAUSE_STOP_ACK ;
614+
615+ //Log.i(TAG, "End of native init, stop everything (exit0)");
563616 System .exit (0 );
564617 }
565618
0 commit comments