Expected:
In landscape, when exiting the app, the startForeground() should be called and a notification should be displayed.
On rotation screen in app, no notification should be set (which is the case).
What happen:
When the smartphone is in landscape mode, the service do not start in foreground when exiting the app.
This is due to onConfigurationChanged(). Many home launcher lock screen in vertical mode. Thus, when exiting the app in horizontal mode, a screen rotation is triggered, calling the onConfigurationChanged. The var configurationChange is set to true. Thus, onUnbind does not his job even if the app is exiting:
override fun onUnbind(intent: Intent): Boolean {
Log.d(TAG, "onUnbind()")
// MainActivity (client) leaves foreground, so service needs to become a foreground service
// to maintain the 'while-in-use' label.
// NOTE: If this method is called due to a configuration change in MainActivity,
// we do nothing.
if (!configurationChange && SharedPreferenceUtil.getLocationTrackingPref(this)) {
Log.d(TAG, "Start foreground service")
val notification = generateNotification(currentLocation)
startForeground(NOTIFICATION_ID, notification)
serviceRunningInForeground = true
}
// Ensures onRebind() is called if MainActivity (client) rebinds.
return true
}
Hi,
Expected: In landscape, when exiting the app, the
startForeground()
should be called and a notification should be displayed. On rotation screen in app, no notification should be set (which is the case).What happen: When the smartphone is in landscape mode, the service do not start in foreground when exiting the app.
This is due to
onConfigurationChanged()
. Many home launcher lock screen in vertical mode. Thus, when exiting the app in horizontal mode, a screen rotation is triggered, calling theonConfigurationChanged
. Thevar configurationChange
is set totrue
. Thus,onUnbind
does not his job even if the app is exiting: