Widget update frequency problem

johnb4a

Member
Licensed User
Longtime User
Hi,

I have a widget and i am trying to set the update frequency.

I am using a preference manager (list) having options 1 hr and 24 hr to set the update frequency. it is working fine but if the frequency is set to 24 hr and the user changes it to every 1 hr, the changes or the updates only reflects after the previous set period. it this case only after 24 hr. how can i get changes reflect immediately? it should immediately start updating every 1 hr rather waiting for 24 hr.

B4X:
Sub Service_Start (StartingIntent As Intent)

If rv.HandleWidgetEvents(StartingIntent) = False Then
         
      rv_RequestUpdate
   End If
   
If manager.GetString("list2") = "1 hr" Then
   
StartServiceAt("", DateTime.Now + 60 * DateTime.TicksPerMinute, True)
   

Else If manager.GetString("list2") = "24 hr" Then

StartServiceAt("", DateTime.Now + 1440 * DateTime.TicksPerMinute, True)

End If
   
End Sub


how can i do this.

thanks in advance.
 

johnb4a

Member
Licensed User
Longtime User
Hi Erel,

Below is the code to add the preference screen.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
Dim manager As PreferenceManager
   Dim screen As PreferenceScreen
   End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim btn As Button
   End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("Main.bal")

If FirstTime Then
      CreatePreferenceScreen
      If manager.GetAll.Size = 0 Then SetDefaults
   End If
   
End Sub

Sub SetDefaults
      manager.SetString("list2", "6 hr")
End Sub

Sub btn_Click
   StartActivity(screen.CreateIntent)
End Sub


Sub CreatePreferenceScreen
   screen.Initialize("Settings", "")
      
   cat2.AddList("list2", "Update Frequency", "", "", _
             Array As String("1 hr", "6 hr", "24 hr"))   
      
             screen.AddPreferenceCategory(cat2)
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)'

End Sub


Please let me know when to call StartServiceAt.

Thanks in advance.
 
Upvote 0

johnb4a

Member
Licensed User
Longtime User
Hi Erel,

Thanks for your reply. But if i call Startservice() at Activity_Resume, then each time i close and open the program it will keep updating the widget which i dont want. It should update only if there is any changes. I have checked the below tutorial but nothing much mentioned about the same. Kindly let me know how to do this.

Thanks

John
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…