I want to create a service that runs every 'n' seconds.
Before it was as simple as
Private Sub Service_Start (StartingIntent As Intent)
ToastMessageShow ("RUNNING...", False)
StartServiceAt(Me, DateTime.Now + 60 * 1000, True)
End Sub
The code works, worse in the Log, it always appears in the message
The Starter service should never be started from a receiver.
I already read the tutorials of these links:
Intent Filters - Intercepting SMS messages in the background
https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/
Automatic Foreground Mode:
https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546/
But I guess something has not been clear to me.
I already know that when the application starts, Android automatically starts the services in
AutomaticForegroundMode mode.
I also understood that it is not necessary to use the
StartServiceAt command because the service never ends, (only in rare cases), because Android returns to run the service automatically, in case the service has been closed, because it is not necessary either:
#StartCommandReturnValue: android.app.Service.START_STICKY
I understood that you have to add the
Service.StopAutomaticForeground line to
Service_Start, in order to use
StartServiceAt.
Although that way the program works "Good".
¿Is not it absurd to do it this way, if the service is always running?
I wrote the following lines within a service
Private Sub Service_Start (StartingIntent As Intent)
ToastMessageShow ("RUNNING...", False)
Log(">>> " & DateTime.GetSecond(DateTime.Now))
End Sub
But the message "RUNNING ..." only appears once.
Although the program works and I think I follow the instructions correctly, obviously something is wrong because the Log keeps showing an error message
What bothers me most is the message
The Starter service should never be started from a receiver.
You can see it in the following screenshot:
¿So, what is the correct way to run a service every 'n' seconds?
Regards.