diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index 501891edd..ada0eeeb0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -192,7 +192,32 @@ public class RelayService extends XWService private static boolean inForeground() { - return sInForeground != null && sInForeground; + boolean result = sInForeground != null && sInForeground; + Log.d( TAG, "inForeground() => %b", result ); + return result; + } + + private static void onAppStateChange( Context context, boolean inForeground ) + { + Log.d( TAG, "onAppStateChange(inForeground=%b)", inForeground ); + if ( null == sInForeground || inForeground() != inForeground ) { + sInForeground = inForeground; + // Intent intent = + // getIntentTo( context, + // inForeground ? BTAction.START_FOREGROUND + // : BTAction.START_BACKGROUND ); + // startService( context, intent ); + } + } + + static void onAppToForeground( Context context ) + { + onAppStateChange( context, true ); + } + + static void onAppToBackground( Context context ) + { + onAppStateChange( context, false ); } public static void startService( Context context ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index 7927c4f65..cbbc2e1dc 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -106,9 +106,11 @@ public class XWApp extends Application implements LifecycleObserver { switch( event ) { case ON_RESUME: BTService.onAppToForeground( this ); + RelayService.onAppToForeground( this ); break; case ON_STOP: BTService.onAppToBackground( this ); + RelayService.onAppToBackground( this ); break; } }