Android Question Error message from Starter service

Amalgamated Sugar

Member
Licensed User
Hello all!

I've been a member for a little over a year, so I've mainly been reading posts and tutorials. I've recently tried creating a service that would make a toast message appear every 30 seconds, as a test in concept.

When I run 'StartServiceAt' from within the Starter service, I get the following error message in the logs:

The Starter service should never be started from a receiver.

The toast message stills runs, but the log message is in red, which implies something important. I'm still new at coding, so it's entirely possible that I don't understand Starter service/Services in General completely.

Here is my code:

B4X:
Sub Process_Globals
 LogColor("Process_Globals being created from Starter service.", Colors.Magenta)
 Dim testString As String

End Sub

Sub Service_Create
 testString = "This is a test from the Starter service"

End Sub

Sub Service_Start (StartingIntent As Intent)
 ToastMessageShow(testString, False)
 StartServiceAt(Me, DateTime.Now + 30000, True)
 
End Sub
 

Peter Simpson

Expert
Licensed User
Longtime User
You should never try to start the starter service, it starts itself.
Create a new service module and put your code in there, now start your new service module using StartService(...) from the original starter module.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've recently tried creating a service that would make a toast message appear every 30 seconds, as a test in concept.
Note that it is not possible to use StartServiceAt to start the service every 30 seconds. The OS will ignore it at some point. The minimum interval is 10 minutes or more.

If you really want to do something every 30 seconds then you should use a foreground service that is kept running.
 
Upvote 0

Jeremy Tipton

Member
Licensed User
Would it make more sense to use a timer to do something every 30 seconds?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Timer2 As Timer
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("youActivityName")
      
    Timer2.Initialize ("Timer2",30000)
    Timer2.Enabled = True
  
End Sub
 
Last edited:
Upvote 0
Top