I created a service that is supposed to perform a backup of the database in my app every night at 11:30. It performs a backup every night at 11:30 but it also seems to perform one every time I open my app. I would prefer it to only backup once per day.
Here is the code for the service start
And here is the code in my main activity. This is where I think the issue is.
Here is the code for the service start
B4X:
Sub Service_Start (StartingIntent As Intent)
Dim hours As Long
Dim minutes As Long
Dim nextruntime As Long
hours = 23
minutes = 30
Dim tt As Long
tt = hours * DateTime.TicksPerHour + minutes * DateTime.TicksPerMinute
Dim NowDay As Long
NowDay = DateTime.DateParse(DateTime.Date(DateTime.Now))
Dim CurrentTime As Long
CurrentTime = DateTime.Now - NowDay
If tt > CurrentTime Then
nextruntime = NowDay + tt
Else
nextruntime = NowDay + DateTime.TicksPerDay + tt
End If
Log("NextRunTime:" & nextruntime & " Date:" & DateTime.Date(nextruntime) & "Time:" & DateTime.Time(nextruntime))
StartServiceAt("",nextruntime,True)
autoproemail 'This sub zips the database and emails it
End Sub
And here is the code in my main activity. This is where I think the issue is.
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Load the layout
Activity.LoadLayout("Menu")
StartService(Backup)