Android Question Widget logic

boten

Active Member
Licensed User
Longtime User
Suppose a widget needs updating itself on specific times (top of the hour, midnight, etc....), then
is this the proper logic for it? Especially the rv_RequestUpdate in Service_Start ???

B4X:
Sub Process_Globals
   Dim rv As RemoteViews
End Sub

Sub Service_Create
   rv = ConfigureHomeWidget("layout", "rv", 0, "My Wid",True)
End Sub

Sub Service_Start (StartingIntent As Intent)
   If rv.HandleWidgetEvents(StartingIntent) Then Return
   rv_RequestUpdate  '<--- need this to update widget when service wakes up
End Sub

Sub rv_RequestUpdate
  ' update widget remote views
  rv.SetText(....
   
  rv.UpdateWidget
   
  Dim nxt as Long
  ' compute next time service should wake up
  nxt=........
  StopService("")
  StartServiceAt("",nxt,False)
End Sub

Sub rv_Disabled
   StopService("")
   CancelScheduledService("")
End Sub

Sub Service_Destroy
End Sub
 

boten

Active Member
Licensed User
Longtime User
.....
Another option is to let it update every x minutes without calling StartServiceAt. You can then decide whether you need to do anything or wait for the next schedule.

"every X minutes" (where X>=30, widget lower limit) might be too late. If need update EXACTLY at top of hour then we might miss the correct timing
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top