D
Deleted member 103
Guest
Hi,
I use this code for my widget.
It actually works fine, just sometimes the numbers for the time disappear, and I need to restart the widget.
Where could the error be?
I use this code for my widget.
It actually works fine, just sometimes the numbers for the time disappear, and I need to restart the widget.
Where could the error be?
B4X:
#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
Public textsize As Int
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("frmWidget", "rv", 0, "HomeClock", True)
rv.SetTextSize("lblTime", textsize)
DateTime.TimeFormat="HH:mm"
DateTime.DateFormat="EEEE, dd MMM"
End Sub
Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then Return
'Reschedule the service every minute, so the clock gets updated correctly
StartServiceAt(Me, TimeToNextMinute, False)
rv_RequestUpdate
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