Bug? Widget bug, updatewidget fired but widget not get updated

ducphu

Active Member
Licensed User
Longtime User
Hi All,

I actually posted this related bug in question section. https://www.b4x.com/android/forum/threads/canvas-on-widget-not-properly-displayed.48614/

Initially I think that it due to the canvas or imageview, but later I realize that the bug can happen with label also.

- Summary: As tittle, widget bug, updatewidget fired but widget not get updated
- Bug details: This seems to be a random bug. Compile and install the apps. Add a few widget to homescreen. Sometimes, the widget just appear as a blank label, imageview... Check log. Rv.Updatedwidget is called. No error observed. For screenshoot, please refer to https://www.b4x.com/android/forum/threads/canvas-on-widget-not-properly-displayed.48614/

I have no clue that this bug is due to B4A or due to my device. My device is xperia Z, running android 4.4.4
I need help to investigate and hope to fix this bug.
 

ducphu

Active Member
Licensed User
Longtime User
No. Actually the first widget is more likely to have problem. If I try continue to add the 2nd and 3rd.. some of them may work.
 

ducphu

Active Member
Licensed User
Longtime User
Ok I will upload my project later when I'm back home.
FYI, I tested a few widgets and all of them have this bug.
1. AHClock widget from corwin. In this widget, corwin used only label with text. Most of the time the widget will load correctly, but sometimes the bug will happen. However, the chance is really low.
2. Homewidget, from Erel tutorial. This widget has label and button. About half of the times, the widget failed to load. When this happens, the label doesn't show current time and the button is not responsed (no click sound)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are missing resources files.

If you can try to reproduce it in a smaller project.

Homewidget, from Erel tutorial. This widget has label and button. About half of the times, the widget failed to load. When this happens, the label doesn't show current time and the button is not responsed (no click sound
I never encountered this issue and I ran it many times.
Make sure to test widgets in release mode.
 

ducphu

Active Member
Licensed User
Longtime User
Hi Erel,

Just heard from my friend that he encountered this error also and what he did is to uninstall the B4A-Bridge + app, restart the phone and reinstall everything again. He said this fix the problem. I will try out this later to see if it works. Will update again.
 

ducphu

Active Member
Licensed User
Longtime User
Ok. I tested. I use 2 widgets, one is my own widget with many imageviews and canvas, and one is eral's widget from the tutorial.
After restart the phone, if I run Erel's one first, it works well, no bug. Then I follow to run my widget. Now bug appears. After that, again I run Erel's one. Now Erel's one also has bug :p After that, the bug seems to remain there any no matter which widget I run, the bug is there. The only way to get rid of the bug is to restart the phone.

So, I think the problem here is, once a widget with many imageviews and canvas are loaded, OS or B4A can't handle it and the memory somehow getting bug which cant be recovered until a restart.
 

ducphu

Active Member
Licensed User
Longtime User
Ok, now I know why the bug happens. But, for my widget, which is a monthly calendar, I have to display the date in a 7x6 views. I want some of the texts will be in bold, italic... under some conditions. If I use label, I can't set the text style on runtime. Now I also can't use many imageviews to draw text due to the limitation... So, is there any solution available?
 

ducphu

Active Member
Licensed User
Longtime User
Hi Erel, I use canvas to draw on bitmap size 20x20dip. I think the problem is I have too many imageviews (7x6 = 42) to handle.
 

ducphu

Active Member
Licensed User
Longtime User
You mean 20x20dip is still too big?

Just a doubt, if I use a loop function to loop through each imageview and calculate the date which then to be draw as text, may it "overload" the memory and cause the bug?

Also, if I have 7x6 imageviews, should I use img(7,6) As Bitmap or just reuse 1 bitmap?
 

corwin42

Expert
Licensed User
Longtime User
The Bitmap for the RemoteView is set with RemoteViews.setImageViewBitmap(). If you google for it, you will find several posts on Stackoverflow with the same issue like yours. One good explanation is here http://stackoverflow.com/questions/10160497/setimageviewbitmap-not-working-in-android-widget

If you have 42 imageviews in your widget with 20x20dip in size it is too big. The buffer for serialization is 1MB in size. If you have a Scale 2 display your image is 40x40 pixel with 32 bit depth. For your 42 imageviews this is 2MB.

Check if you see the following error in the unfiltered log: !!! FAILED BINDER TRANSACTION !!!

Another good explanation of the problem is here: https://groups.google.com/forum/#!msg/android-developers/KKEyW6XdDvg/wgetULOJq3QJ
 

ducphu

Active Member
Licensed User
Longtime User
Ok I see, for my device the scale is 3 so it is 4.5mb.... may I ask, for those new phone on the market what is the highest scale up to now?
And, is the rv.settext for label counted in this 1mb?
 
Last edited:

ducphu

Active Member
Licensed User
Longtime User
I reduce the bitmap size to 5x5dip, and no more bug. But then the new problem is, as Erel mentioned, the image will be stretched to fill the 20x20 imageview, so all the text look very blur and not sharp.
 
Last edited:
Top