Other [new feature] Starter Service

Not open for further replies.


B4X founder
Staff member
Licensed User
Longtime User
One of the challenges that developers of any non-small Android app need to deal with, is the multiple possible entry points.
Updated tutorial is available here: https://www.b4x.com/android/forum/threads/starter-service-consistent-entry-point.57599/

During development in almost all cases the app will start from the Main activity.
I'm sure that many programs start with code similar to:
Sub Activity_Create (FirstTime As Boolean)
If FirstTime Then
  SomeBitmap = LoadBitmap(...)
  'additional code that loads application-wide resources
End If
End Sub
Everything seems to work fine during development. However the app "strangely" crashes from time to time on the end user device.
The reason for these crashes is that the OS can start the process from a different activity or service. For example if you use StartServiceAt and the OS kills the process while it is in the background.
Now the SQL object and the other resources will not be initialized.

The next version of B4A will include a new (optional) feature that will make it much simpler to manage this issue.
The process will always start from the Starter service. The Starter service will be created and only then the activity or service that were supposed to be started will start.
This means that the Starter service is the best place to initialize all the application-wide resources.
Other modules can safely access these resources.

This is an optional feature. You can safely remove the Starter service and you can also add this service to existing projects.
Last edited:


Licensed User
Longtime User
I am reading a comport (inputstream) using a timer every 100ms. Is it ok to put such a timer event into the starter service to read the input buffer into a process_global variable? (because this service should always be running and I want to read the variable from different activities)
Upvote 0
Not open for further replies.