Android Question Run routine every X minutes?

tsteward

Well-Known Member
Licensed User
Longtime User
My app has a webview at the bottom of the main screen showing the latest additions/comments made by users.
It would be nice to reload this webview every 10 minutes or so while the app is running.

Would I use a timer to do this?
or is there a better way.

Perhaps load in the B4XPage_Appear if it hasn't refreshed in the last 10 min.
Ie load app and load webview
start timmer
if I go to other pages and come back withing 10 minutes then do nothing
if I go to other pages and come back > 10 minutes thenreload

Thoughts, suggestions, examples?
 

tsteward

Well-Known Member
Licensed User
Longtime User
That was just where my mind went.
At this time I have decided to record the current time in the DB and each time the user visits the main screen B4XPage_Appear I check the time against this and reload the webview if the difference is > 10 minutes.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I would use sleep(10 * 60 * 60 * 1000) or sleep(36000000) in a infinite loop. I have almost totally eliminated timers from my work.
B4X:
Do While True      'Or some switch when you don't need to do this anymore
    'Load your web page
    Sleep(36000000)
Loop
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
if I go to other pages and come back withing 10 minutes then do nothing
[O.T.]
I assume your project is of type B4XPages, since you call them "pages".
So it's important to remember that a WebPage is always active, so you could update its WebView even while another WebPage is displayed.

That said, you should probably do both, either use a timer, in case the user lingers on the page for a long time, and reload the WebView in the Appear event.
 
Upvote 0
Top