Android Question Home Screen Widget update issue

asonnenb

New Member
Licensed User
Longtime User
Hi, I need some help with a widget home screen

Find bellow part of the widget receiver module I had developped:


widget receiver:
Sub Process_Globals

    Dim rv As RemoteViews
    Dim jobHttp_widget As HttpJob
    Dim hashcode as String
    
End Sub

Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    
    If FirstTime Then
        rv = ConfigureHomeWidget("WidgetLayout", "rv", 30, "Test")
        jobHttp_widget.Initialize("jobHttp_widget", Me)
    End If
    rv.HandleWidgetEvents(StartingIntent)
    
End Sub

Private Sub rv_RequestUpdate

jobHttp_widget.Download("https://myurl.com?id=" & hashcode)   

End Sub

Sub Image1_Click
    
jobHttp_widget.Download("https://myurl.com?id=" & hashcode)
    
End Sub



This 'hashcode' depends on the user that had authenticated in the Main Activity.

I want the widget to update when I hit Image1 even when the APP is closed.

If I set this 'hashcode' on the Main module as the following:

widget receiver:
widget.hashcode = "somehashcode"

...the widget updates when I hit Image1 , but ONLY if I have the APP running on the background.

If I close the APP, the widget will not work.

I had tried alternatives (ex: using keyvaluestore on the widget receiver) but with no success.

Any idea ? thanks in advance
 

asonnenb

New Member
Licensed User
Longtime User
Thanks Erel. I had adjusted the httpJob.

I am using KeyValueStore and CallSubDelayed2. It seems to solve the "widget updating"problem" I had described.

This is the widget receiver code:

widget:
Sub Process_Globals
    
    Dim rv As RemoteViews
    Dim kvs As KeyValueStore
 
End Sub



Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    
    
    If FirstTime Then
        rv = ConfigureHomeWidget("WidgetLayout", "rv", 30, "Me Poupe")
    End If
    rv.HandleWidgetEvents(StartingIntent)
    

End Sub

Private Sub rv_RequestUpdate
   
    update_widget
    
End Sub


Sub Image1_Click
    
    update_widget

End Sub


Sub update_widget()
    
    
    If kvs.IsInitialized = False Then
        kvs.Initialize(File.DirInternal,"tx.dat")
    End If
    
    
    If kvs.ContainsKey("client") Then
        
    
        Dim jobHttp_widget As HttpJob
        jobHttp_widget.Initialize("",Me)
        jobHttp_widget.Download("https://myurl?id=" & kvs.Get("client"))
        Wait for (jobHttp_widget) JobDone(jobHttp_widget As HttpJob)
        If jobHttp_widget.Success Then
        
            Dim parser As JSONParser
        
            parser.Initialize(jobHttp_widget.GetString)

            '......

        End If
        jobHttp_widget.Release
        rv.UpdateWidget
    
    
    End If
    
End Sub

'this Sub update_client is called from Main using CallSubDelayed2

Sub update_client(client As Int)
    
    If kvs.IsInitialized = False Then
        kvs.Initialize(File.DirInternal,"tx.dat")
    End If
    
    kvs.Put("client", client)
    
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…