I wrote a simple alarm base on Erel's code. Hope it can help
Public Sub NextTimeRun(sHour As Int, sMinute As Int) As Long
DateTime.DateFormat = "dd/MM/yyyy HH:mm:ss"
Log("AlarmHours: " & sHour)
Log("AlarmMinutes: " & sMinute)
Dim today As Long
today = DateTime.DateParse(DateTime.Date(DateTime.Now)) 'Sets today at 12:00 AM
alarm = today + sHour * DateTime.TicksPerHour + sMinute * DateTime.TicksPerMinute
If alarm < DateTime.Now Then alarm = DateTime.Add(alarm, 0, 0, 1)
TimerDate = DateTime.Date(alarm) & " " & DateTime.Time(alarm)
Log(DateTime.Date(alarm) & " " & DateTime.Time(alarm)) 'check the logs to see the set date and time
'Calculate time to alarm
Dim h, m As Int
h = Floor((alarm - DateTime.Now) / DateTime.TicksPerHour)
m = ((alarm - DateTime.Now) - h * DateTime.TicksPerHour) / DateTime.TicksPerMinute
'ToastMessageShow("The next site query will be performed after: " & NumberFormat(h, 2, 0) & " hour(s) and " & NumberFormat(m, 2, 0) & " minute(s)", True)
TimeRemaining = NumberFormat(h, 2, 0) & ":" & NumberFormat(m, 2, 0)
Dim isleepTime As Long = DateTime.Now + ((h*60*60*1000)+(m*60*1000))
Log("SleepTime: " & isleepTime)
Return isleepTime
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 10 * DateTime.TicksPerSecond, True)
ToastMessageShow("test service and toast",True)
End Sub
Sub Service_Destroy
StopService("")
CancelScheduledService("")
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim noti As Notification
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("L1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
noti.Initialize
noti.Light = False
noti.Vibrate = False
noti.OnGoingEvent = True
noti.Sound = False
noti.Icon = "icon"
noti.SetInfo("test","tes","")
noti.Notify(1)
StartService(serviceHitung)
End Sub