Android Question Starter Service Clarification

mangojack

Expert
Licensed User
Longtime User
In This Thread re B4A / VB Input Box ... @Erel states,

You should never see this error message. It means that you removed the starter service. That is a mistake.

Using B4XPage projects, it is now habit that I remove the Starter Service and to my knowledge it has not created any issue.

I'm now a little confused whether I am doing wrong.
 

josejad

Expert
Licensed User
Longtime User
I think it depends on the situation and your needs... there are several cases:

In this post about B4XPages, you can read: "In most cases we don't need to use the starter service."
And sometimes it can be a solution to remove it, but it's not recommended, because you may need it
 
Upvote 0

PaulMeuris

Active Member
Licensed User
Until i started updating my apps to Android 14 i never had a problem with the Starter Service as I never used it.
But now i'm writing/updating apps for Android 14.
It seems that the starter service can get stuck in the foreground state resulting in a blank screen.
Once this happens (in release mode) the apps remains stuck and needs to be reinstalled.
This is the Service_Start subroutine (i added some log comments):
B4X:
Sub Service_Start (StartingIntent As Intent)
    LogColor("service start active trying to stop automatic foreground",Colors.Red)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
    LogColor("service start finished",Colors.Red)
End Sub
In this log the app (B4XPages) presents a blank screen after the app was removed from the recent apps list (swiped or tapped on close all).
In this log the app (default activity) also presents a blank screen.
Conclusion: if you don't need to use the Starter Service then remove it from the project.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Thanks to all.
I was under the impression a while back that the Starter Service was not an absolute necessity,
more so if using B4XPages ... but @Erels statement caused a tremor in the frontal cortex region.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
The Starter Service also contains the exception handler event

B4X:
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User

Initially I never used that Sub... but at present it is a good reason to rethink inclusion of the Starter Service.

Thanks
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In This Thread re B4A / VB Input Box ... @Erel states,



Using B4XPage projects, it is now habit that I remove the Starter Service and to my knowledge it has not created any issue.

I'm now a little confused whether I am doing wrong.
Probably that user wrote some Sub in the Starter and then removed it. I don't think removing the empty Starter will cause any problems; but you can avoid removinng it, this will still not cause any problems.
 
Upvote 0

PaulMeuris

Active Member
Licensed User
A new empty project. The normal Click button is not available.
The first time it is available but when you remove the app from the recent apps list it will get stuck on my device.

The app runs in release mode on a Android 14 device.
It will get stuck if you leave the starter module in the project.
In this code i have commented the line 19 but left the starter module in the project.
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

End Sub

Sub Service_Start (StartingIntent As Intent)
'    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
Line 19 code doesn't stop the foreground state. The method Service.StopAutomaticForeground doesn't seem to work in Android 14.
The only way to make this app work normal is to remove the starter module!
But don't take my word for it, just try it out and see for yourself.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
To support Android 14 correctly I think that it's mandatory B4A 13 with new SDK and Java 19.
But I could be wrong.
Also check this info
https://www.b4x.com/android/forum/t...getsdkversion-34-and-services.162140/#content
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…