Widget update rate slow?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Widget update rate slow?

Post by mbirth » 16 Dec 2017 00:33

Hi,

I'm currently rebuilding a Tasker task with Automagic. All gets triggered by the app "Motion Detector" (Beta version is far more recent) which sends an intent. The triggered flow sets a variable to getElapsedRealtimeMillis() plus 90 seconds. Another flow gets triggered when the variable is changed. That flow shows a widget overlay with a green bar spanning the whole display width which length property gets modified ... so basically the green bar shrinks until the 90 seconds are over. This is done via a loop that modifies the width property and a sleep of 333ms. (And emergency stop after 3000 operations per minute which shouldn't be reached.)

My problem is: The overlay widget is not refreshing properly UNLESS I'm in the flow. While in the flow view/editor, everything works fine, the widget gets refreshed properly. But as soon as I leave the flow editor and get back to the flow list or my home screen, the widget only seems to get refreshed every 10-20 seconds or even less often. Why is that?

This is on an ASUS Nexus 7 with Android 5.1.1.
Last edited by mbirth on 16 Dec 2017 00:40, edited 1 time in total.
BlackBerry KEY2, Android 8.1.0

User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Re: Widget update rate slow?

Post by mbirth » 16 Dec 2017 00:35

BlackBerry KEY2, Android 8.1.0

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Widget update rate slow?

Post by Desmanto » 16 Dec 2017 08:58

I have hard time to execute your flow. I used gravity box to show battery bar on the top of the screen and it overlaps with you widget. Even worse, the battery bar also green color :lol:
I have to offset the y to see the widget.

It is a nice idea to do something like this. Last time I just saw implementation with notifiication progress, and now with widget. But I don't have the need for this yet, will bookmark for future reference.

Widget refresh speed is limited to twice per second, or 500 ms before next refresh. If you try to set it lower, it will skip a lot and give unpredictable result as you experienced. The reason why it refresh properly when in the flow editor is because other elements execution increase by ten fold in flow editor view. Average element execution time is about 3-4 ms, but will increase up to 30-40 ms when viewed in flow editor (depends on the phone). Because automagic have to redraw the red color denoting the element which are currently running.

I can see the loop has 6 elements, with 5 elements executed before the next sleep. If each element takes 35 ms, total will be 175 ms. Added to 333 ms, will give 508 ms, which is higher than the minimum limit. When you execute the flow outside of the flow editor, per element execution now speed up to 3-4 ms. Let's say it is 5 ms x 5 = 25 ms. Added to 333 ms, only 358 ms, which is way below the minimum. Thus the widget now doesn't refresh properly.

You have to set the sleep above 500 ms. You can try to reduce a little (I tried with 480ms still working), but not much difference. So maximum animation speed is 2 fps, not more than that. I think it was ever requested to have simple animation feature using the widget. But I seems to takes a lot of time to implement it properly.

For the loop, All of them are mostly script and expression. After you have finished testing, it is better to consolidate them all into single script action (including the sleep). The flow will be more efficient and you don't need to set the AES to 3000, since the loop is inside the script. Scripting block feature is one of the things that makes me fall in love with automagic.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Re: Widget update rate slow?

Post by mbirth » 16 Dec 2017 12:59

Desmanto wrote:It is a nice idea to do something like this. Last time I just saw implementation with notifiication progress, and now with widget. But I don't have the need for this yet, will bookmark for future reference.
Thanks. I have an old tablet on my desk that's showing some statistics about my home server (using JuiceSSH and glances). And although it's always connected to its charger, I somehow found it nice for it to turn off when nobody is looking. And to see when it's about to turn off, I implemented this green bar.
Desmanto wrote:Widget refresh speed is limited to twice per second, or 500 ms before next refresh. If you try to set it lower, it will skip a lot and give unpredictable result as you experienced. The reason why it refresh properly when in the flow editor is because other elements execution increase by ten fold in flow editor view.
Thanks, this is the info I needed. However, I'd wish there was a way to increase the refresh rate. With Tasker, a sleep of only 100ms was no problem at all. And since the device is constantly on AC power, a higher power consumption is no problem at all.
Desmanto wrote:For the loop, All of them are mostly script and expression. After you have finished testing, it is better to consolidate them all into single script action (including the sleep). The flow will be more efficient and you don't need to set the AES to 3000, since the loop is inside the script. Scripting block feature is one of the things that makes me fall in love with automagic.
Yep, those Script blocks are also a thing I love. But it's always a struggle between "readability" (=small Scripts, more blocks) and putting everything in a single Script block.
BlackBerry KEY2, Android 8.1.0

Post Reply