Hi all,
after a couple of days of use, the solution outlined in post #12 above seems to work. At least on my Android 10 device.
So, schematically, I copy here the essential parts of it for the benefit of others (and for
@Erel to amend and/or to suggest a correct/proper way to do it)
As said above I have two receivers:
dgmd and
rcboot
The first one (dgmd) is the "regular" one. It's intended to update home widget's labels every 30 minutes, called by the OS
The second one (rcboot) is my way to cope with the boot/reboot of the device when Internet is not yet available.
Fundamentally, dgmd is started by the OS when installing the widget and after a boot/reboot. In the first case you can expect the Internet to be already available so everything should work as usual. After a boot/reboot there's the concrete possibility that when the receiver is called by the OS, Internet access isn't available, so dgmd starts in a minute the second receveir.
The second receiver (rcboot) has the sole task to test for Internet availability and, in case of failing, to try again in a minute.
Once Internet access is available, rcboot calls back in dgmd to immeditaley update its labels (not waiting for the 30 minutes delay of the OS)
That's all
Note: since this is a quick and dirty solution for my device and personal use, I didn't bother with Internet on/off or other situations. As said in post #12 for a general solution I would rather use a server querying the weather api tocache data at given intervals, while listening to queries from user devices to server that data.
dgmd receiver
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
LogColor("dgmday: receiver_receive: "&FirstTime, 0xFFFF0000)
Log(StartingIntent)
If FirstTime Then
rv = ConfigureHomeWidget("lytWidgetD", "rv", 30, "DG Meteo Day",True)
commons.Initialize
Wdata.Initialize
End If
rv.HandleWidgetEvents(StartingIntent)
End Sub
Private Sub rv_RequestUpdate
If Not(rcboot.InternetOK) Then
StartReceiverAt(rcboot, DateTime.Now + (1 * DateTime.TicksPerMinute), False) 'run this receiver again in 1 minute
rv.SetText("lblTown", "Internet not yet available")
Else
LastUpdate = DateTime.Now
'read remote data
wait for (ReadNewData) Complete(res1 As Boolean)
rv.SetText("lblTown", Wdata.Get("Tname"))
'update some othern labels
End If
rv.UpdateWidget
End Sub
rcboot receiver
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
LogColor("rcboot: receiver receive: "&FirstTime, 0xFFFF0000)
If Not(InternetOK) Then
Dim j As HttpJob
j.Initialize("", Me) 'name is empty as it is no longer needed
j.Download("www.google.com")
j.GetRequest.Timeout = 5000
Wait For (j) JobDone(j As HttpJob)
Log("rcboot success: "&j.Success)
InternetOK = j.Success
If j.Success Then
CallSubDelayed(dgmd, "UpdtdgmD")
Else
StartReceiverAt(Me, DateTime.Now + (1 * DateTime.TicksPerMinute), False) 'run this receiver again in 1 minute
End If
End If
End Sub