Android Question Widget issue

giggetto71

Active Member
Licensed User
Longtime User
Hi guys,
I am getting crazy while trying to modify my app working widget. The widget is very simple and has been working for months. Now I am tryng to modifiy but whatever Views I add in the L1 layout if I try to SetVisibility in the code I get :

Widget Error:(NoSuchFieldException) java.lang.NoSuchFieldException: widgetservice_imageview2

B4X:
Public Sub rv_UpdateWidget
    Dim ActiveAlerts As Int, ii As Int, ToBeAckCounter As Int, TempElem As AlertObj,AlertTextLocal As String
    Try
    If IsPaused("MQTTService") = True Then
       rv.SetVisible("lblNextAlert",False)
       rv.SetVisible("lblPrevAlert",False)
       rv.SetText("lblAlertWdgt","" )
       rv.SetText("lblAlertsCounter","0")
       rv.SetVisible("lblTobeAck",False)
       rv.SetVisible("lblTobeAckCounter",False)
       rv.SetText("lblBrokerOK", "Disconnected")   
       rv.SetTextColor("lblBrokerOK",Colors.Black)   
       'rv.SetVisible("ImageView2",True) 'if I uncomment this line I get that error...
       rv.UpdateWidget
       Return
    End If
    .....


The L1 is shown below and I have really only added that ImageView2.
Why am I getting that error? What am I missing.
thanks!

1645867673692.png
 

udg

Expert
Licensed User
Longtime User
Did you try to remove the existing widget from ther device before installing the new version?
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
yes. I did. it really looks like I cannot change anything..even if I change the text property of an existing label view, it does not get updated..
is there a way to "reset" somehow so that the modified L1 layout file gets processed? It's almost like I am editing another L1 file. every thing I try to change in L1 does not processed somehow..very strange..
 
Upvote 0

udg

Expert
Licensed User
Longtime User
A few points to check
1. if rv stands for a RemoteViews object than its event should be Sub rv_RequestUpdate not rv_UpdateWidget
2. "If IsPaused("MQTTService") = True Then" - add a log for the False condition to be sure you're not in that case
3. try removing the try-catch to see the error message(s) in the log

Following your post #3 I strongly suspect point 1 above, but a general check won't hurt anyway.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
thanks for your reply.
I understand what you say in point 1. I changed slightly Erel's main example and I have:
B4X:
public Sub rv_RequestUpdate
    SetStatus
    rv_UpdateWidget
End Sub

so I can keep all the code executed in the rv_UpdateWidget. this is currently working fine.
I really think it's not a code problem because I restarted from the previous version (which works just fine) but even that version does not reflect any change I do in the layout file. For example. The lblBrokerStatus label view has a text shown in the widget as "MQTT Broker status". If I change in the layout file to "MQTT_Broker status", the the added "_" does not appear in the widget which remains "MQTT Broker status". Same if I add a new view (no code), just a label with a text. it just does not appear...



1645954591560.png
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Ok, so now it runs fine but you still have problem updating layout L1.
Did you try Tools/Clean project?
What happens if you save the updated layout with a different name (changing your code accordingly)?
Eventually, remove once again the ols widget from the device, restart the device then install the updated widget.
Another option could be to change the widget's name, but it sounds a bit excessive..
 
Last edited:
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
I will try later today, but i already tried most of the auggested checks. I think i will probably restart from a single view with nearly zero code and start adding..maybe this will force the app to reset the widget..
 
Upvote 0
Top