Android Question Widget problem again

Nickelgrass

Active Member
Licensed User
Longtime User
Hello,
I have an app that includes a widget. In the widget service module I set a value in a file to 1 when the widget is created and set the value to 0 when the widget is disabled.
But the disabled event is never called. I uninstalled an installed new several times to see if some "ghost" widgets where causing the problem, but it still acts like this. The event is never called, I cheked it with a log().
Is there no way to determine by some OS stuff if the widget is currently on the homescreen or not??? Seems a bit strange that the only way to determine this is by a file entry. My widget updates several times a day, so that would be a lot of power wasted if it wanst on the screen. Is there a complete documentation on the widget? I only found the two tutorials.

B4X:
Sub Service_Create
    file.write(file.dirinternal, "widgeton.txt", "1")
    wid = ConfigureHomeWidget("mywidget", "wid", 0, "some label", True)
    Log("SETWIDGET")
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy
End Sub

Sub wid_RequestUpdate
    wid.UpdateWidget
End Sub

Sub wid_Disabled
    Log("DISABLE") '<------- Never done
    file.write(file.dirinternal, "widgeton.txt", "0")
    StopService("")
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
I think you forgot the initializing of that service

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

Maybe the events are only called if you do this at service_start.
 
Upvote 0

Nickelgrass

Active Member
Licensed User
Longtime User
Thanks, that seemed to have been one of the issues. The other was that I didnt cancel a schedule. But the question remains, is there not a way to test if the widget is on the screen? this would be a much cleaner way of handling it.
 
Upvote 0
Top