Android Question Update Widget at specific time

Nickelgrass

Active Member
Licensed User
Longtime User
Hello,
the widget can be set to update itself at a certain interval via ConfigureHomeWidget. But how can I set this to to a specific time? I need to fire the update at several times a day but not over night or weekends. So I need it to fire for example monday to saturday at 10, 12, 14 and 16 oclock.
Can I somehow set the StartServieAt on the widget (if it is actually put on homescreen) and each time calculate the next StartServiceAt time?

Thanks!

Regards
 

Nickelgrass

Active Member
Licensed User
Longtime User
Ok, thanks!
One nother small question. I Have a second service in my app that runs all the time. This service would need to update some data and then make the widget update itself IF it is on the screen.

Can I reliably determine if the widget is active with the ispaused("widget_service") and then simply call an update sub from the widget service if it is running?
 
Upvote 0

Nickelgrass

Active Member
Licensed User
Longtime User
Ok, thanks! But what if the widget is not put on the homescreen at the time? will the callsubdelayed then be ignored?
 
Upvote 0

Nickelgrass

Active Member
Licensed User
Longtime User
Thanks for the help! Setting a value to 1 works fine.
I have a widget wid = ConfigureHomeWidget("widgetlayout", "wid", 0, "somename"). But for some reason the "Sub wid_Disabled" is not called. In this sub I set the value back to 0.

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Dim wid As RemoteViews
End Sub
Sub Service_Create
    wid = ConfigureHomeWidget("widgetlayout", "wid", 0, "somename")
    includes.set_setting("widgeton", "1") 'sets a value in file to 1
End Sub

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

Sub Service_Destroy

End Sub

Sub wid_RequestUpdate
    update
End Sub

Sub wid_Disabled
    includes.set_setting("widgeton", "0") 'sets a value in file to 0
    StopService("")
End Sub

The wid_Disabled is never called. What am I doing wrong. When loging the events I only see Service (widget) start but never destroyed. Even if I close the widget. :(:(:(

Another very strange thing ist that when I run my app I get this log:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Service (widget) Create **
** Service (widget) Start **
But I dont touch it and the service widget is not started in my code. Why does it pause and then reasume an start the service??? When I deinstall the widget I also get the Service start log.
 
Last edited:
Upvote 0

Nickelgrass

Active Member
Licensed User
Longtime User
Ok, it seemed that a second widget was still on screen as a sort of invisible ghost from a previous installation. After deinstalling and then reinstalling the app (not just installing a new version) it was ok.
Thanks a lot Erel!!! I was really in despair for that one. :)
 
Upvote 0
Top