Android Question Does B4A 8.0 add a persistent notification icon for services?

Inman

Well-Known Member
Licensed User
I have a service with the following attributes
B4X:
#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

Administrator
Staff member
Licensed User
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

Inman

Well-Known Member
Licensed User
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
Top