There are two functions I need to run with a minimum time gap between them. For reasons beyond the scope of this question, at first I was trying to control the timing from a process running in the webview (via a JavascriptInterface):
webView.post(() -> functionA());
// ... wait 2 secs in javascript and then...
webView.post(() -> functionB());
Whilst this worked fine most of the time, for one user in particular it seemed that the two functions were sometimes running immediately after each other (still in the right order, but just without the time gap).
On reflection, this is understandable, if it is the case that posting a runnable to a handler will just put them in a queue, without any guarantee to maintain the relative timing based on when they were placed in the queue.
So, if that is the case, then my new strategy is to forget about controlling the timing from the javascript running in the webview, and just control it in the Java directly.
So the question is... does using postDelayed()
as follows guarantee at least a minimum time gap between the two functions being run?
webView.post(() -> functionA());
webView.postDelayed(() -> functionB(), 2000);
I feel that it ought to have the desired effect, but am wary that maybe it amounts to the same as what I was doing... putting functionB
into the queue 2 secs after functionA
, with no guarantee that they will actually maintain that time gap between them