I Inman Well-Known Member Licensed User Longtime User May 30, 2018 #1 I have a service with the following attributes Code: Copy #StartAtBoot: True #StartCommandReturnValue: android.app.Service.START_STICKY The project <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21"/>. It is compiled with android-26/android.jar. I developed this app on B4A 7.30 and everything was working fine. Recently I compiled the app using B4A 8.0 and some of my users are reporting that every time their phone restarts, the app has a persistent notification icon. I read about Automatic Foreground Mode and thought maybe that is the issue. So I set Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_NEVER but now my users are saying the app doesn't start at boot at all and that they need to manually start by opening the app. Once again, on B4A 7.30 it was fine. Is this a known limitation of B4A 8.0/Android 8.0? Any way to fix this?
I have a service with the following attributes Code: Copy #StartAtBoot: True #StartCommandReturnValue: android.app.Service.START_STICKY The project <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21"/>. It is compiled with android-26/android.jar. I developed this app on B4A 7.30 and everything was working fine. Recently I compiled the app using B4A 8.0 and some of my users are reporting that every time their phone restarts, the app has a persistent notification icon. I read about Automatic Foreground Mode and thought maybe that is the issue. So I set Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_NEVER but now my users are saying the app doesn't start at boot at all and that they need to manually start by opening the app. Once again, on B4A 7.30 it was fine. Is this a known limitation of B4A 8.0/Android 8.0? Any way to fix this?
Erel B4X founder Staff member Licensed User Longtime User May 30, 2018 #2 It is indeed related to the automatic foreground mode. You should call Service.StopAutomaticForeground in Service_Start instead of setting it to never. If your app is distributed through Google Play then you should set the targetSdkVersion to 26 and properly handle the foreground mode. Note that sticky services is not recommended with newer versions of Android. The OS will kill the service very quickly if it is not in foreground mode. Upvote 0
It is indeed related to the automatic foreground mode. You should call Service.StopAutomaticForeground in Service_Start instead of setting it to never. If your app is distributed through Google Play then you should set the targetSdkVersion to 26 and properly handle the foreground mode. Note that sticky services is not recommended with newer versions of Android. The OS will kill the service very quickly if it is not in foreground mode.
I Inman Well-Known Member Licensed User Longtime User May 30, 2018 #3 I understand. I will learn the transition to SDK 26 soon. But for the time being, please clarify this. If I set targetSdkVersion=21 use Sticky Service set StartAtBoot to True call Service.StopAutomaticForeground compile with B4A 8.0 using android-26/android.jar will it be similar to compiling with B4A 7.30, such that there will be no persistent notification and that the system will restart the service after it kills (since it is a Sticky Service)? Upvote 0
I understand. I will learn the transition to SDK 26 soon. But for the time being, please clarify this. If I set targetSdkVersion=21 use Sticky Service set StartAtBoot to True call Service.StopAutomaticForeground compile with B4A 8.0 using android-26/android.jar will it be similar to compiling with B4A 7.30, such that there will be no persistent notification and that the system will restart the service after it kills (since it is a Sticky Service)?
Erel B4X founder Staff member Licensed User Longtime User May 31, 2018 #4 Yes. However there was a report of an issue with sticky services and Android 8 so make sure to test it. Upvote 0
Yes. However there was a report of an issue with sticky services and Android 8 so make sure to test it.