I tried to write a little alarm app by using service module.
Main activity code:
B4X:
Sub SetSchedule_ItemClick (Position As Int, Value As Object)
Dim start, now, atTime As Long
DateTime.TimeFormat = "HH:mm"
start = DateTime.TimeParse(Value) ' parse time from xml, format like 14:32
now = DateTime.Now
If start > now Then
atTime = start - now
Msgbox("It's OK", "Set schedule")
StartServiceAt(notischedule, atTime, False)
Else
Msgbox("Cannot set schedule in past time","Error")
End If
End Sub
Service module name "notischedule" code:
B4X:
Sub Process_Globals
Dim Noti As Notification
End Sub
Sub Service_Create
Noti.Initialize
Noti.Icon = "icon"
Noti.Light = True
Noti.Sound = True
Noti.Vibrate = True
Noti.AutoCancel = True
End Sub
Sub Service_Start
Noti.SetInfo("Hey, it's time now!", "Alarm", Main)
Noti.Notify(1)
End Sub
Compile ok but it doesn't work and there's no notification icon. What did I miss? Please help.
Here is a very simple example that starts the service in 10 seconds:
B4X:
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
StartServiceAt(s1, DateTime.Now + 10 * DateTime.TicksPerSecond, False)
End Sub
Service module named S1:
B4X:
Sub Process_Globals
Dim Noti As Notification
End Sub
Sub Service_Create
Noti.Initialize
Noti.Icon = "icon"
Noti.Light = True
Noti.Sound = True
Noti.Vibrate = True
Noti.AutoCancel = True
End Sub
Sub Service_Start
Noti.SetInfo("Hey, it's time now!", "Alarm", Main)
Noti.Notify(1)
End Sub
When we use Service, AndroidManifest.xml will be modified and in my case it's read-only (because I used AdMob lib before). I think you should mention about AndroidManifiest.xml in Service tutorial.
More questions: How to set 3 alarms on 3 different times? How to list down all the alarms that set? How to remove 1 alarm? And why there's no document about Service (I only found your tutorials).