@ Override public int onStartCommand ( Intent intent , int flags , int startId ) { if ( intent == null ) { return START_STICKY ; } String action = intent . getAction ( ) ; if ( ACTION_START_FOREGROUND . equals ( action ) ) { if ( ! SPF . get ( ) . isConnected ( ) ) { SPF . get ( ) . connect ( ) ; } SPF . get ( ) . notifyProximityStatus ( false ) ; //false because it's starting startInForeground ( ) ; Log . d ( TAG , "Started in foreground" ) ; } else if ( ACTION_STOP_FOREGROUND . equals ( action ) ) { //notify to the middleware that i killed the proximity service SPF . get ( ) . notifyProximityStatus ( true ) ; //true because it's killing stopForeground ( true ) ; mIsStartedForeground = false ; Log . d ( TAG , "Foreground stopped" ) ; } return START_STICKY ; }
Triggered by the front end to keep spf service active in foreground