@@ -193,7 +193,7 @@ protected void onPostExecute(String result) {
193
193
mActivity .getPackageName (), PackageManager .GET_META_DATA ).metaData ;
194
194
195
195
PowerManager pm = (PowerManager ) mActivity .getSystemService (Context .POWER_SERVICE );
196
- if ( mActivity .mMetaData .getInt ("wakelock" ) == 1 ) {
196
+ if (mActivity .mMetaData .getInt ("wakelock" ) == 1 ) {
197
197
mActivity .mWakeLock = pm .newWakeLock (PowerManager .SCREEN_BRIGHT_WAKE_LOCK , "Screen On" );
198
198
mActivity .mWakeLock .acquire ();
199
199
}
@@ -450,35 +450,32 @@ public void appConfirmedActive() {
450
450
public void considerLoadingScreenRemoval () {
451
451
if (loadingScreenRemovalTimer != null )
452
452
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 () {
463
465
@ Override
464
466
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 ();
475
472
}
476
- };
477
- loadingScreenRemovalTimer = new Timer ();
478
- loadingScreenRemovalTimer .schedule (removalTask , 5000 );
473
+ });
479
474
}
480
- }
481
- });
475
+ };
476
+ loadingScreenRemovalTimer = new Timer ();
477
+ loadingScreenRemovalTimer .schedule (removalTask , 5000 );
478
+ }
482
479
}
483
480
484
481
public void removeLoadingScreen () {
@@ -589,14 +586,30 @@ protected void onResume() {
589
586
if (this .mWakeLock != null ) {
590
587
this .mWakeLock .acquire ();
591
588
}
592
- Log .v (TAG , "onResume()" );
589
+ Log .v (TAG , "onResume(), mSDLThread exists yet: " + ( mSDLThread != null ) );
593
590
try {
594
591
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
+ }
595
604
} catch (UnsatisfiedLinkError e ) {
596
605
// Catch resume while still in loading screen failing to
597
606
// 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" );
598
609
}
599
610
considerLoadingScreenRemoval ();
611
+ Log .v (TAG , "onResume() done in PythonActivity, " +
612
+ "mSDLThread exists yet: " + (mSDLThread != null ));
600
613
}
601
614
602
615
@ Override
@@ -606,6 +619,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
606
619
} catch (UnsatisfiedLinkError e ) {
607
620
// Catch window focus while still in loading screen failing to
608
621
// call native function (since it's not yet loaded)
622
+ return ; // no point in barging further
609
623
}
610
624
considerLoadingScreenRemoval ();
611
625
}
0 commit comments