Android Question Widget doesn't update

MrKim

Well-Known Member
Licensed User
Longtime User
It appears that widgets won't always update in release mode if
B4X:
 #BridgeLogger: True

I update when I exit the program and it doesn't happen. It appears that if I force the program closed then it will update once.

I was logging the code that updates the widget and it was hitting all of the code, it just didn't update.

Here is a snippet of the code I was running. It was posting to the log OK but not setting my label visible or displaying the CV - or at least not the bitmap.

B4X:
    If i2 > 0 Then
        Log(1)
        SS = It.Get(0)
        RV.SetText("Label1", SS.Txt)
        RV.SetVisible("Label1", True)
        RV.SetTextColor("Label1", SS.TxtClr)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV1", BMP)
    Else
        RV.SetText("Label1", "List is empty. Top 6 in your list will display here.")
        RV.SetVisible("Label1", True)
        RV.SetTextColor("Label1", Colors.White)
        CV.DrawColor(Colors.Blue)
        RV.SetImage("IV1", BMP)
    End If

Remming and unremming the LOG(1) also made no difference.
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Moved to the questions forum.

Where is the call to RV.UpdateWidget?

Here is the entire sub. It WAS working just fine, seems to have stopped after 7.01 upgrade but not positive about that. Interestingly If I delete the widget and then put it back it updates immediately.

RestoreWidgetData is called in Main Activity_Pause.
All of the Log statements (remmed here) happen but the widget does not update.

Additional testing has revealed (I think this is what mislead me into thinking it was a logger bug.):
If I delete the widget and then reinstall it, it updates immediately.
I can then open my app, make changes, and it will update - ONE TIME. After that it no longer updates when I close the app.
It is set to update with or without userclosed.

B4X:
Public Sub RestoreWidgetData
Dim R As RandomAccessFile, It As List, SS As NotePoperties, i2 As Int
Try
    R.Initialize(File.DirInternal, "SwipeList.swl", False)
    It = R.ReadB4XObject(0)
    R.Close
    'ToastMessageShow("Refreshing widget data", False)
    i2 = It.Size
    'ToastMessageShow("Size " & i2, False)
    Dim CV As Canvas, BMP As Bitmap, Rect As Rect
    Rect.Initialize(0, 0, 155, 50)
    BMP.InitializeMutable(155dip, 50dip)
    CV.Initialize2(BMP)
    If i2 > 0 Then
'        Log(1)
        SS = It.Get(0)
        RV.SetText("Label1", SS.Txt)
        RV.SetVisible("Label1", True)
        RV.SetTextColor("Label1", SS.TxtClr)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV1", BMP)
    Else
        RV.SetText("Label1", "List is empty. Top 6 in your list will display here.")
        RV.SetVisible("Label1", True)
        RV.SetTextColor("Label1", Colors.White)
        CV.DrawColor(Colors.Blue)
        RV.SetImage("IV1", BMP)
    End If
    If i2 > 1 Then
'        Log(2)
        SS = It.Get(1)
        RV.SetText("Label2", SS.Txt)
        RV.SetVisible("Label2", True)
        RV.SetTextColor("Label2", SS.TxtClr)
        Dim CV As Canvas, BMP As Bitmap, Rect As Rect
        Rect.Initialize(0, 0, 155, 50)
        BMP.InitializeMutable(155dip, 50dip)
        CV.Initialize2(BMP)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV2", BMP)
    Else
        RV.SetVisible("Label2", False)
        RV.SetVisible("IV2", False)
    End If
    If i2 > 2 Then
'        Log("3  " & SS.Txt & "  " & SS.BClr)
        SS = It.Get(2)
        RV.SetText("Label3", SS.Txt)
        RV.SetVisible("Label3", True)
        RV.SetTextColor("Label3", SS.TxtClr)
        Dim CV As Canvas, BMP As Bitmap, Rect As Rect
        Rect.Initialize(0, 0, 155, 50)
        BMP.InitializeMutable(155dip, 50dip)
        CV.Initialize2(BMP)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV3", BMP)
    Else
        RV.SetVisible("Label3", False)
        RV.SetVisible("IV3", False)
    End If
    If i2 > 3 Then
'        Log(4)
        SS = It.Get(3)
        RV.SetText("Label4", SS.Txt)
        RV.SetVisible("Label4", True)
        RV.SetTextColor("Label5", SS.TxtClr)
        Dim CV As Canvas, BMP As Bitmap, Rect As Rect
        Rect.Initialize(0, 0, 155, 50)
        BMP.InitializeMutable(155dip, 50dip)
        CV.Initialize2(BMP)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV4", BMP)
    Else
        RV.SetVisible("Label4", False)
        RV.SetVisible("IV4", False)
    End If
    If i2 > 4 Then
'        Log(5)
        SS = It.Get(4)
        RV.SetText("Label5", SS.Txt)
        RV.SetVisible("Label5", True)
        RV.SetTextColor("Label5", SS.TxtClr)
        Dim CV As Canvas, BMP As Bitmap, Rect As Rect
        Rect.Initialize(0, 0, 155, 50)
        BMP.InitializeMutable(155dip, 50dip)
        CV.Initialize2(BMP)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV5", BMP)
    Else
        RV.SetVisible("Label5", False)
        RV.SetVisible("IV5", False)
    End If
    If i2 > 5 Then
'        Log(6)
        SS = It.Get(5)
        RV.SetText("Label6", SS.Txt)
        RV.SetVisible("Label6", True)
        RV.SetTextColor("Label6", SS.TxtClr)
        Dim CV As Canvas, BMP As Bitmap, Rect As Rect
        Rect.Initialize(0, 0, 155, 50)
        BMP.InitializeMutable(155dip, 50dip)
        CV.Initialize2(BMP)
        CV.DrawColor(SS.BClr)
        RV.SetImage("IV6", BMP)
    Else
        RV.SetVisible("Label6", False)
        RV.SetVisible("IV6", False)
    End If
'    Log("Update")
    RV.UpdateWidget
Catch
    ToastMessageShow(LastException.Message, True)
End Try
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Additional update I changed the panel background color and it turns out the the TEXT (Label) is updating just fine. it is the Canvas that is not updating.
Simply recompiling the code and installing it will cause the widget to update correctly without actually opening the program after installation.
Note the first item in the list always updates correctly.
 
Last edited:
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Sigh, another embarrassing faux pas on my part. I wasn't setting the ImageViews visible. When I originally wrote the code All of the slots were always visible so they never got turned off so it always worked. Once I deleted enough items to turn them off they were not getting made visible again. It always worked when reinstalling because the default was visible.

Sorry I wasted your time.
 
Upvote 0
Top