Problem with StartServiceAt

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
My application needs to send a notification every day (conditional) at the same time.
But it is the user of the application who must set the time of sending.
Here is my code but it does not work. What's wrong, what is the correct code?

In Main Module
B4X:
Sub BtnParamHeure_Click

        Dim HeureAverto as long

   Dim td As TimeDialog
   Dim txt As String
   txt = "14:30:00"
   Td.Hour = DateTime.GetHour(DateTime.TimeParse(txt))
   'DateTime.TimeParse("16:13:00") 
   Td.Minute = DateTime.GetMinute(DateTime.TimeParse(txt))
   Td.Is24Hours = True
   ret = Td.Show("Entrer l'heure où voulez être prévenue", "Heure de l'avertissement", "OK", "Annuler", "", Null)
   If ret = DialogResponse.POSITIVE Then   
      HeureAverto = Td.TimeTicks 'Date choisie par le picker
      LblParamHeure.Text = DateTime.Time(HeureAverto)
      
   Else
      Return
   End If

'Lance la notif si coché
MyHeure = DateTime.Time(HeureAverto)

  If ChkNotif.Checked=True   Then
StartServiceAt("Alarme",DateTime.TimeParse(MyHeure),True)
         
  Else
   'StopService(Alarme) 'Met fin à la notif
   CancelScheduledService(Alarme)
  End If

End Sub

In Module Service "Alarme"

B4X:
Sub Service_Start (StartingIntent As Intent)

RECUP_alarme 'Récupère les variables dont notif, alarm et HeureAverto

If notif =True Then
   
   Dim TheHeure As String
   DateTime.TimeFormat = "HH:mm"
   TheHeure = DateTime.Time(HeureAverto)

      If alarm = True Then
         Dim n As Notification
         n.Initialize
         n.Icon = "logo"
         n.SetInfo("Contraception", alerte, "Main") 
         'Change Main (above) to "" if this code is in the main module.
         n.Vibrate = True
         n.Notify(1)
      End If
   StartServiceAt("",TheHeure + (60000 * 60 * 24)  ,True)
   'StartServiceAt("",DateTime.TimeParse(TheHeure),True)
        'StartServiceAt("",DateTime.TimeParse(TheHeure + (60000 * 60 * 24) ),True)
Else
   CancelScheduledService("")
End If
End Sub

I tried multis ServiceStartAt formulas, nothing works.
Thank you for your help
 
Last edited by a moderator:

ciginfo

Well-Known Member
Licensed User
Longtime User
The service starts for the first time in Main Module "StartServiceAt("Alarme",DateTime.TimeParse(MyHeure),True)"
It is after for repeating every day, it bugs at " StartServiceAt("",TheHeure + (60000 * 60 * 24) ,True)" in Module service
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
HeureAverto is in a file.
Put simply. What is the code to start a service every day at the same time knowing that it is the user of the application which determines the time.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…