Hi all,
I'm updating some old code of mine about a weather forecast home widget in order to use Receivers.
It seems to work ok until the device gets rebooted.
Here it is the log
The code in the affected receiver is as follows
ReadNewData and ReadFiveDays are quite simple. Something like:
Since compiling-installing-running seems to work ok, it looks like that the Download can't be done in the Receiver soon after reboot 'cause the Main activity is not started yet and so there's no proper context for it. If it's so, how should the widget be designed?
I'm updating some old code of mine about a weather forecast home widget in order to use Receivers.
It seems to work ok until the device gets rebooted.
Here it is the log
Logger connected to: 52003f8fb48055e3
--------- beginning of main
--------- beginning of system
*** Receiver (dgmd) Receive (first time) ***
dgmday: receiver receive: true
(Intent) Intent { act=android.appwidget.action.APPWIDGET_ENABLED flg=0x10000010 cmp=eu.dgc.dgmeteo/.dgmd }
*** Receiver (dgmd) Receive ***
dgmday: receiver receive: false
(Intent) Intent { act=android.appwidget.action.APPWIDGET_UPDATE flg=0x14000010 cmp=eu.dgc.dgmeteo/.dgmd (has extras) }
dgmDay: inizio aggiornamento dati
*** Receiver (dgmd) Receive ***
dgmday: receiver receive: false
(Intent) Intent { act=android.appwidget.action.APPWIDGET_UPDATE_OPTIONS flg=0x10000010 cmp=eu.dgc.dgmeteo/.dgmd (has extras) }
sending message to waiting queue of uninitialized activity (submitjob)
--------- beginning of main
--------- beginning of system
*** Receiver (dgmd) Receive (first time) ***
dgmday: receiver receive: true
(Intent) Intent { act=android.appwidget.action.APPWIDGET_ENABLED flg=0x10000010 cmp=eu.dgc.dgmeteo/.dgmd }
*** Receiver (dgmd) Receive ***
dgmday: receiver receive: false
(Intent) Intent { act=android.appwidget.action.APPWIDGET_UPDATE flg=0x14000010 cmp=eu.dgc.dgmeteo/.dgmd (has extras) }
dgmDay: inizio aggiornamento dati
*** Receiver (dgmd) Receive ***
dgmday: receiver receive: false
(Intent) Intent { act=android.appwidget.action.APPWIDGET_UPDATE_OPTIONS flg=0x10000010 cmp=eu.dgc.dgmeteo/.dgmd (has extras) }
sending message to waiting queue of uninitialized activity (submitjob)
The code in the affected receiver is as follows
B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
Log("dgmday: receiver receive: "&FirstTime)
If FirstTime Then
rv = ConfigureHomeWidget("lytWidgetD", "rv", 30, "DG Meteo Day",True)
commons.Initialize
End If
Log(StartingIntent)
rv.HandleWidgetEvents(StartingIntent)
End Sub
Private Sub rv_RequestUpdate
Log("dgmDay: inizio aggiornamento dati")
LastUpdate = DateTime.Now
'aggiorna i dati istantanei della città selezionata
wait for (ReadNewData) Complete(res As Object)
Log("dgmDay: fine ReadNewData")
'aggiorna i dati delle prox 5 fasce orarie prendendoli da quelli settimanali (prox 5 giorni)
wait For (ReadFiveDays) Complete(res As Object)
Log("dgmDay: fine ReadFiveDays")
rv.UpdateWidget
Log("dgmDay: fine aggiornamento dati")
End Sub
ReadNewData and ReadFiveDays are quite simple. Something like:
B4X:
Sub ReadNewData As ResumableSub
Dim j As HttpJob
j.Initialize("", Me) 'name is empty as it is no longer needed
j.Download($"http://api.openweathermap.org/data/2.5/weather?id=${commons.Settings.Get("idtday")}&units=metric&lang=it&appid=${commons.AppKey}"$)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Since compiling-installing-running seems to work ok, it looks like that the Download can't be done in the Receiver soon after reboot 'cause the Main activity is not started yet and so there's no proper context for it. If it's so, how should the widget be designed?