+1
Answered

Auto-refresh (timed refresh) options?

sstava 7 years ago updated by icahill (Administrator) 7 years ago 5
Looking for some suggestions...What are my options if I want to refresh a screen on a timed or periodic basis? (i.e. auto-refresh every 2 hours).

I have a refresh button on the screen, but I would like to have the screen refresh, from the server, on a timed basis even if you didn't press the refresh button.

This would eliminate the problem of someone not realizing they had new content:
1) if they didn't close and reopen the app or
2) if they didn't press the refresh button

Thanks for your thoughts!
Steve,

Is your intention to only set a refresh trigger while the app is open, or do you want content to refresh while the app is running in the background?
At this point, only while it is open.
You could probably write a loop action that uses an extreme delay like 7200 seconds, but what will likely happen is that the clock will only start when you trigger the action for the first time and will have to be restarted when the app resumes or oninits.
<wire>
   <main>
      <panel name="1" width="100" height="100" background="ff0000" onclickup="move"></panel>
    </main>
    <actions>
    <action name="move">
            <sync>
                <assign property="var:count" value="0"/>
                <assign property="var:count2" value="0"/>
                <loop lhs="[var:count]" operator="lte" rhs="5" delay="10">
                    <loop lhs="[var:count2]" operator="lte" rhs="5">
                        <alert message="BOOM [var:count] - [var:count2]"/>
                        <assign property="var:count2" value="[eval: [var:count2] + 1]"/>
                    </loop>
                    <assign property="var:count" value="[eval: [var:count] + 1]"/>
                    <assign property="var:count2" value="0"/>
                </loop>
            </sync>
      </action>
    </actions>       
</wire>
There are probably other ways to do this by putting a delay on a sync block and running a play tag or using a javascript function to poll system time and trigger an action when it meets a certain condition.
Thanks! I like your thought for the javascript/system time approach. I think I will give that a try as well as see how "onresume" works.

I was looking through the documentation and hadn't noticed the "onresume" property, before.

P.S. very excited about the tag. I will have to refactor some of my code to take advantage of that. Many new features...Yay!
Onresume is fairly new considering, ondeviceshake it the latest to be added to the action tag though.