Android Question Where do I have to activate Service_Start?

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello community
I want to check a timestamp on a label every minute and do this with the following code:
B4X:
Sub Service_Start(StartingIntent As Intent)
StartServiceAt(Null, DateTime.Now + 60 * 1000, True)
B4XPages.MainPage.Layout_50.L50_Button1_Click
End sub
Where do I have to activate Service_Start?
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
You need to call StartService([service name]) - probably from your Main activity Activity_Create.

- Colin.
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi Colin,
thank you for your hint.
probably from your Main activity Activity_Create
If i call it from "Main / Sub Activity_Create(FirstTime As Boolean)" the Logfile says:
** Receiver (starter) OnReceive **
The Starter service should never be started from a receiver.
** Service (starter) Start **
-+-+-+- 1 Minute ist vorbei +-+-+-+-+-
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Oh - you didn't mention it is the Starter Service. It will start automatically, so you don't need to do anything.

https://www.b4x.com/android/forum/threads/starter-service-consistent-single-entry-point.57599/

Having said that, you should probably not be doing that from the Starter Service. I'd create a new service & put your code in that, then start that service from Activity_Create. The reason being that the Starter Service runs for as long as the app is running, so you shouldn't be calling StartServiceAt on itself. If you really want to run that functionality from Starter Service, then I guess you could use a timer.

(Sorry - another edit): Or if you are just updating a label on a layout (& by the looks of it it's your main layout) every minute, then why not just use a timer. Set it up in Activity_Create, start it in Activity_Resume & stop it in Activity_Pause.

- Colin.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

Starting at boot or starting scheduled. Both should not be use in starter service!
The starter service should never be explicitly started. This means that if you want to start a service at boot then add a different service.
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
I thought that a timer would consume too much resources in the app, so I wanted to do it through the StartService.
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello Erel, thank you for your expert advice.
A timer will have zero effect on the app performance.
In this case I will use a timer that will check every minute whether a certain time has been reached on a label and then click a button.

Can I keep restarting the timer with "loop"?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…