#Region  Service Attributes
    #StartAtBoot: true
#End Region
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private rv As RemoteViews
End Sub
Sub Service_Create
    rv = ConfigureHomeWidget("frmWidget", "rv", 0, "HomeClock", True)
    rv.SetTextSize("lblTime", 110)
   
    DateTime.TimeFormat="HH:mm"
    DateTime.DateFormat="EEEE, dd MMM"
End Sub
Sub Service_Start (StartingIntent As Intent)
'    Log("StartingIntent.Action=" & StartingIntent.Action)
       
    'Reschedule the service every minute, so the clock gets updated correctly
    StartServiceAt(Me, TimeToNextMinute, False)
    rv_RequestUpdate
    If rv.HandleWidgetEvents(StartingIntent) Then Return   
End Sub
Sub Service_Destroy
End Sub
'Calculate the time to the next full minute
Sub TimeToNextMinute As Long
    Dim ret As Long
    ret = DateTime.Now + DateTime.TicksPerMinute
    ret = ret - (ret Mod DateTime.TicksPerMinute)   
    Return ret
End Sub
Sub SetTime
    rv.SetText("lblTime", DateTime.Time(DateTime.Now))
    rv.SetText("lblDate", DateTime.Date(DateTime.Now))
End Sub
Sub rv_RequestUpdate
    SetTime
    rv.UpdateWidget
End Sub
Sub rv_Disabled
    StopService("")
End Sub