I feel like the simplest solution that doesn't use sleep
would be like this solution from the thread @justinedwards.jle linked.
I wrote up a little example that adapts it to this use case.
I set up two views, one as my landing page and one as the second page.
On the landing page, in the root container, I set up some custom props, redirect_timer
and redirect_at
The top prop, redirect_timer
, is bound to the expression now(1000)
to update once a second. If you want a more precise delay, you could change the 1000
to a smaller number.
I also set up an onStartup
Script event action on the root container:
def runAction(self):
self.custom.redirect_at = system.date.addSeconds(system.date.now(), 5)
This makes sure that as soon as the page loads, the target time is set up for 5 seconds from now.
In the meantime, the prop redirect_timer
also has a change script on it:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
if system.date.isAfter(currentValue.value, self.custom.redirect_at):
system.perspective.navigate("/second-page")
This will call the navigate action once our current time has passed our target time.