From 0a0107dd7fdc5eaadc631141b10b3054fd8d10c5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 09:35:08 -0800 Subject: [PATCH] fix to contact relay in foreground on Oreo+ Background still needs a lot of work. --- .../org/eehouse/android/xw4/RelayService.java | 27 ++++++++++++++++++- .../java/org/eehouse/android/xw4/XWApp.java | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) 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; } }