widget update faild

Fox

Active Member
Licensed User
Longtime User
Hello guys i want to update my widget text every 1 minutes but instead of it they update nothing where is my error here is the code:

'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim rv As RemoteViews
Dim ST As SQL
Dim Cursor As Cursor
End Sub

Sub Service_Create
'Set the widget to update every 1 minutes.
rv = ConfigureHomeWidget("WidgetLayout", "rv", 1, "Widget")
If File.Exists(File.DirInternal,"database.db") Then
ST.Initialize(File.DirInternal, "database.db", False)
rv.UpdateWidget
End If
End Sub

Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub

Sub Service_Destroy

End Sub
Sub rv_RequestUpdate
SetTexting
rv.UpdateWidget
End Sub

Sub rv_Disabled
StopService("")
End Sub


Sub SetTexting
If File.Exists(File.DirInternal,"database.db") Then
rv.SetText("Label1", "Here is the result: " & ST.ExecQuerySingleResult("SELECT count(*) FROM database"))
Else
rv.SetVisible("Label2", True)
End If
rv.UpdateWidget
End Sub
 

Omar

Member
Licensed User
Longtime User
Hey Fox,

From what I understand about the widgets, you cannot have a value less than 30 minutes for the update.

I have not actually tried working with them yet, but I think this is what was mentioned in the tutorial.
 
Upvote 0

Fox

Active Member
Licensed User
Longtime User
Hey Fox,

From what I understand about the widgets, you cannot have a value less than 30 minutes for the update.

I have not actually tried working with them yet, but I think this is what was mentioned in the tutorial.

:BangHead:
ohhh yes... stupid misstake sorry..
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
But there's a way around it. (30 minutes update)

Use a timer :p

Like that:

B4X:
Sub Process_Globals
    Dim Timer1 As Timer
    Timer1.Initialize("Timer1",2000)
    Timer1.Enabled = True
End Sub

Sub Timer1_Tick
    'Do something
    rv.UpdateWidget
End Sub

I hope it works :eek:.

Edit@

Tested, seems to be fine.
 
Upvote 0
Top