Android Question [Solved] Widget updating

stanks

Active Member
Licensed User
Longtime User
hi

i noticed when i use
B4X:
Sub Service_Start (StartingIntent As Intent)
    If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub

my info is d/l only once from the net and widget is updated (once or more idk). but when i use example from
B4X:
https://www.b4x.com/android/forum/threads/update-a-homescreen-widget-more-frequently-than-30-minutes.11329/

info for widget is d/l at least 3 times (and this is for example code....i didn't add all code. original is updated 4 times). is this bug? normal behavior? my bug in code? where is the problem?
i tried this on emulator (genymotion) and on real device. android versions from 4.1.x to 5.1.1

thanks
 

stanks

Active Member
Licensed User
Longtime User
no matter i put sub for d/l and JobDone in widget service or starter service and this happens only first time the widget is started
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
widget service and second example starter service, and call to that sub is in rv_RequestUpdate
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
sub that d/l xml and JobDone sub are in widget service that updates the widget (or in the starter service....no matter....result is the same). and call to the sub that d/l xml is in rv_RequestUpdate. like this:

B4X:
...
Sub Service_Start (StartingIntent As Intent)
'    rv.UpdateWidget
'    If rv.HandleWidgetEvents(StartingIntent) Then Return
    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then Return

    ' Handle the widget events
    If rv.HandleWidgetEvents(StartingIntent) = False Then
        ' If the action is not handled by HandleWidgetEvents() then we
        ' probably were called by StartService() or StartServiceAt().
        ' So just update the widget.
        rv_RequestUpdate
    End If

    ' We have to be sure that we do not start the service
    ' again if all widgets are removed from homescreen
    If StartingIntent.Action <> "android.appwidget.action.APPWIDGET_DISABLED" Then
        ' 1min = 60000 ms
        Dim osv As Long = DateTime.Now + (interval * 60000)
        StartServiceAt("", osv, False)
    End If

end sub
...
Sub rv_Disabled
    CancelScheduledService("")
    StopService("")
End Sub

Sub DLXml
    Dim job1 As HttpJob

    job1.Initialize("test", Me)
    job1.Download(link)
End Sub

Sub rv_RequestUpdate
    DLXml
...
end sub

Sub JobDone(job As HttpJob)
    If job.Success = True Then
        Select job.JobName
            Case "test"
               rss.parse...
               UpdateWidgetInfo
    Else
        Log ("Error: " & job.ErrorMessage)
      End If
    job.Release
End Sub

Sub UpdateWidgetInfo
    ...
    rv.UpdateWidget
Ens Sub
if i uncomment first two lines in Service_Start and comment all other, i didn't d/l xml 3 times but only once.
interval is int as for example 15
if you add i as int in global and put i = i + 1 and Log(i) in rv_RequestUpdate you will get (at least i get that) 3 times d/l xml.
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
with above code...as user will choose in options activity (every X minutes). but i don't understand why with above code my widget calls d/l sub 4 times when i add widget to the screen? is that normal behavior?

thanks
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
thank you. here is the output:

B4X:
(Intent) Intent { act=android.appwidget.action.APPWIDGET_ENABLED flg=0x10 cmp=...
(Intent) Intent { act=android.appwidget.action.APPWIDGET_UPDATE_OPTIONS flg=0x10 cmp=...
(Intent) Intent { act=com.motorola.blur.home.ACTION_SET_WIDGET_SIZE flg=0x10 cmp=...

can this be avoid somehow so i don't have so much d/l's for first time when widget is added to the screen?

thanks
 
Upvote 0
Top