Android Question Starter service behavior

Alessandro71

Well-Known Member
Licensed User
Longtime User
I see in the logs that the Starter service is created and started when the app is run.
I've also seen that sometimes the Starter service is also stopped by the OS while the app is still running (maybe when it's in background, I haven't traced the actual condition)

My question is: once the Starter service is stopped, it will remain stopped, or is there any event that may cause it to be started again?

The reason behind my question is the initialization code I'm putting in Service_Start: I don't want it to be executed again while the app is still running, and I must be sure that Service_Start won't be invoked again.
 

Cableguy

Expert
Licensed User
Longtime User
see this as an example of a continuously running service

 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
The reason behind my question is the initialization code I'm putting in Service_Start: I don't want it to be executed again while the app is still running, and I must be sure that Service_Start won't be invoked again.
you can also test for if a view of your choice is initialized and if so, skip the initialization process
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User

I rephrase my question: I do not need the Starter service to be continuosly running, I just need to be sure that it's not started again after the system stop it
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
If the system stops the starter service, your app is in fact "killed" and so next time you run it, the Activity_Create(FirstTime As Boolean) will be true, so all the initialization will occur.
Again, you can either test if firsttime is false, which will mean the app is comming from the background to the foreground, and/or if a particular view is already inilialized, in order to prevent doing it again
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
maybe I'm wrong, but I'm quite sure I've seen sometimes the Starter service being stopped with the app still running, in a B4XPages project.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User

this is interesting: I hope it's still valid for B4A 13 and SDK 34
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
apparently I was not dreaming: here is the log from an app of mine starting and then being put in background

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**

the Starter service is apparently destroyed, but I think the "(ignored)" message means that it is actually still in the running state
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
the Starter service is apparently destroyed, but I think the "(ignored)" message means that it is actually still in the running state
exactly, but its easy to check. as I said, if the service is destroyed and the app is in background, then the next time it runs "FirstTime" value will be true
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…