Android Question Problem with Starter Service

marcick

Well-Known Member
Licensed User
Longtime User
I have some initializations in Starter Service and I want to be sure everything is starting from scratch when the app is launched after it has been closed with the back button.

So I have this code

B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed=True Then StopService ("Starter")
End Sub

Closing the App with the Back Button I see in the Log that the Starter Service is destroyed, but launching the App again It is not recreated and restarted.

Where I'm wrong ?
 

DonManfred

Expert
Licensed User
Longtime User
You should not stop (or start) the starter service by yourself
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I know I shouldn't but it's better for me that the code in the Starter Service is executed everytime the App is launched. And the App has several possible entry point.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I know I shouldn't but it's better for me that the code in the Starter Service is executed everytime the App is launched. And the App has several possible entry point.
This is exactly the purpose of the Starter service. You don't need to stop it yourself.
Pressing on the back key doesn't kill the process. The process global variables will be kept alive until the process is killed.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I understand but:
I have for example to check if a db exists and if not create it.
The App has multiple entry point so I have put that check in the starter service and it works ok.
Suppose now the db is deleted form outside. If I close and restart the App the starter service is not started again until I reboot the device. So my App crash here and there when it tries to access to the db.
Do I have to repeat that check (db exists) for every possible App entry point or there is a way to execute starter service every time the App is launched ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ok, understand how it works.
StopService(Starter) stop the service but not in a way it is started again when you restart the App (maybe after some time but not immediately).
Need to do some modifications.
Thanks
 
Upvote 0
Top