fix to contact relay in foreground on Oreo+

Background still needs a lot of work.
This commit is contained in:
Eric House 2018-11-29 09:35:08 -08:00
parent b23b837009
commit 0a0107dd7f
2 changed files with 28 additions and 1 deletions

View file

@ -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 )

View file

@ -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;
}
}