@@ -193,7 +193,7 @@ protected void onPostExecute(String result) {
193193 mActivity .getPackageName (), PackageManager .GET_META_DATA ).metaData ;
194194
195195 PowerManager pm = (PowerManager ) mActivity .getSystemService (Context .POWER_SERVICE );
196- if ( mActivity .mMetaData .getInt ("wakelock" ) == 1 ) {
196+ if (mActivity .mMetaData .getInt ("wakelock" ) == 1 ) {
197197 mActivity .mWakeLock = pm .newWakeLock (PowerManager .SCREEN_BRIGHT_WAKE_LOCK , "Screen On" );
198198 mActivity .mWakeLock .acquire ();
199199 }
@@ -450,35 +450,32 @@ public void appConfirmedActive() {
450450 public void considerLoadingScreenRemoval () {
451451 if (loadingScreenRemovalTimer != null )
452452 return ;
453- runOnUiThread (new Runnable () {
454- public void run () {
455- if (((PythonActivity )PythonActivity .mSingleton ).mAppConfirmedActive &&
456- loadingScreenRemovalTimer == null ) {
457- // Remove loading screen but with a delay.
458- // (app can use p4a's android.loadingscreen module to
459- // do it quicker if it wants to)
460- // get a handler (call from main thread)
461- // this will run when timer elapses
462- TimerTask removalTask = new TimerTask () {
453+ if (PythonActivity .mSingleton != null &&
454+ mAppConfirmedActive &&
455+ loadingScreenRemovalTimer == null ) {
456+ Log .v (TAG , "loading screen timer Runnable() launched." );
457+ // Remove loading screen but with a delay.
458+ // (app can use p4a's android.loadingscreen module to
459+ // do it quicker if it wants to)
460+ TimerTask removalTask = new TimerTask () {
461+ @ Override
462+ public void run () {
463+ // post a runnable to the handler
464+ runOnUiThread (new Runnable () {
463465 @ Override
464466 public void run () {
465- // post a runnable to the handler
466- runOnUiThread (new Runnable () {
467- @ Override
468- public void run () {
469- PythonActivity activity =
470- ((PythonActivity )PythonActivity .mSingleton );
471- if (activity != null )
472- activity .removeLoadingScreen ();
473- }
474- });
467+ Log .v (TAG , "loading screen timer Runnable() finished." );
468+ PythonActivity activity =
469+ ((PythonActivity )PythonActivity .mSingleton );
470+ if (activity != null )
471+ activity .removeLoadingScreen ();
475472 }
476- };
477- loadingScreenRemovalTimer = new Timer ();
478- loadingScreenRemovalTimer .schedule (removalTask , 5000 );
473+ });
479474 }
480- }
481- });
475+ };
476+ loadingScreenRemovalTimer = new Timer ();
477+ loadingScreenRemovalTimer .schedule (removalTask , 5000 );
478+ }
482479 }
483480
484481 public void removeLoadingScreen () {
@@ -589,14 +586,30 @@ protected void onResume() {
589586 if (this .mWakeLock != null ) {
590587 this .mWakeLock .acquire ();
591588 }
592- Log .v (TAG , "onResume()" );
589+ Log .v (TAG , "onResume(), mSDLThread exists yet: " + ( mSDLThread != null ) );
593590 try {
594591 super .onResume ();
592+ if (mSDLThread == null && !mIsResumedCalled ) {
593+ // Ok so SDL2's onStart() usually launches the native code.
594+ // However, this may fail if native libs aren't loaded yet at that point
595+ // (due ot our loading screen) so we may need to manually trigger this,
596+ // otherwise code would only launch by leaving & re-entering the app:
597+ Log .v (TAG , "Loading screen workaround: triggering native resume" );
598+ if (mSDLThread == null && mCurrentNativeState == NativeState .RESUMED ) {
599+ // Force a state change so SDL2 doesn't just ignore the resume:
600+ mCurrentNativeState = NativeState .PAUSED ;
601+ }
602+ resumeNativeThread (); // native resume to call native code
603+ }
595604 } catch (UnsatisfiedLinkError e ) {
596605 // Catch resume while still in loading screen failing to
597606 // call native function (since it's not yet loaded)
607+ Log .v (TAG , "failed to call native onResume() because libs " +
608+ "aren't loaded yet. this is expected to happen" );
598609 }
599610 considerLoadingScreenRemoval ();
611+ Log .v (TAG , "onResume() done in PythonActivity, " +
612+ "mSDLThread exists yet: " + (mSDLThread != null ));
600613 }
601614
602615 @ Override
@@ -606,6 +619,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
606619 } catch (UnsatisfiedLinkError e ) {
607620 // Catch window focus while still in loading screen failing to
608621 // call native function (since it's not yet loaded)
622+ return ; // no point in barging further
609623 }
610624 considerLoadingScreenRemoval ();
611625 }
0 commit comments