Android Question Problem with StartServiceAT

Isac

Active Member
Licensed User
Longtime User
Currently I can get a service delay of 10 seconds

How to delay a service for x days via EditText?


B4X:
date=DateTime.Now+10*1000
 
StartServiceAt(start,date,False)


Maybe I need to use:

B4X:
date=DateTime.Add
 

Isac

Active Member
Licensed User
Longtime User
Can someone check?

thank you



B4X:
Sub Button1_Click
Dim Giorni As Int 
 
Try
    Giorni = EditText1.Text
Catch
    ToastMessageShow("Inserisci un giorno numerico",True)
    Return
End Try
Dim DATA As Long=DateTime.DateParse(EditText4.Text) 
Try
    DATA =DateTime.DateParse(EditText4.Text)
Catch
    ToastMessageShow("Non riesco a ricavare la data",True)
    Return
End Try
Dim date As Long
 
date=DateTime.Add(DATA,0,0,Giorni)
 
 
StartServiceAt(start,date,False)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Have a look at "DateUtils" Library.
B4X:
'Adds a Period to the given date instance. Do not forget to assign the result.
Public Sub AddPeriod(Ticks As Long, Per As Period) As Long
    Ticks = DateTime.Add(Ticks, Per.Years, Per.Months, Per.Days)
    Ticks = Ticks + Per.Hours * DateTime.TicksPerHour + Per.Minutes * DateTime.TicksPerMinute + _
        Per.Seconds * DateTime.TicksPerSecond
    Return Ticks
End Sub
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
Currently I have error on this line the program closes

B4X:
date=DateUtils.AddPeriod(DATA,Giorni)
Types do not match warning 22

B4X:
Sub Button1_Click

  Dim Giorni As Int
  Dim DATA As Long

Try
    Giorni = EditText1.Text
Catch
    ToastMessageShow("Inserisci un giorno numerico",True)
    Return
End Try
Dim DATA As Long=DateTime.DateParse(EditText4.Text)
Try
    DATA =DateTime.DateParse(EditText4.Text)
Catch
    ToastMessageShow("Non riesco a ricavare la data",True)
    Return
End Try
Dim date As Long
'periodo(DATA,Giorni)

date=DateUtils.AddPeriod(DATA,Giorni)

StartServiceAt(start,date,False)

End Sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Giorni is INT
Giorni must be of type Period (see library-documentation for dateutils)

btw. I just found this...

B4X:
Datenew = DateTime.Add(dateOld, 0, 9, 0)

Set Dateold to now and then call
B4X:
Datenew = DateTime.Add(dateOld, 0, 0, 1)
to add 1 day to dateold

I think this could be more interesting for you and your problem...

PS: It would be HELPFUL if you post part of the error-log instead of just "Currently I have error in this line"!
 
Last edited:
Upvote 0
Top