Search for StartServiceAt.
Sub Service_Start (StartingIntent As Intent)
'Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
StartServiceAt(Me, NextTimeInstance(05, 30) ,True)
End Sub
Sub NextTimeInstance (Hours As Int, Minutes As Int) As Long
Dim today As Long = DateTime.Now
today = DateUtils.SetDateAndTime(DateTime.GetYear(today), DateTime.GetMonth(today), _
DateTime.GetDayOfMonth(today), Hours, Minutes, 0)
If today < DateTime.Now Then
Dim p As Period
p.Days = 1
Dim tomorrow As Long = DateUtils.AddPeriod(today, p)
Return tomorrow
Else
Return today
End If
End Sub
StartServiceAt(Me, NextTimeInstance(18, 06) ,True)
StartActivity(act1)
The permanent notification is related to the automatic foreground mode: https://www.b4x.com/search?query=automatic+foreground+modeAlso, I do not want the permanent notification to appear, what should I do?
This is exactly the purpose of NextTimeInstance. It calculates the next scheduled time.i want to start the service every day, once in the morning and once in the evening, depending on the time the user chooses in setting page
You will need to do some reading.
The permanent notification is related to the automatic foreground mode: https://www.b4x.com/search?query=automatic+foreground+mode
This is exactly the purpose of NextTimeInstance. It calculates the next scheduled time.
Sleep(0)
Service.StopAutomaticForeground
StartServiceAt(Me, NextTimeInstance(24, 01) ,True)
StartActivity(act1)
StartServiceAt(Me, NextTimeInstance(01, 10) ,True)
StartActivity(act2)
StartServiceAt(Me, NextTimeInstance(KVS.GetDefault("H-PM" , "21"), KVS.GetDefault("M-PM" , "15")) ,True)
You don't need to start any service when the app is opened. Only call StartServiceAt.i don't want to start the service when I open the app every time, i just want to start service when time = the specific time in the label