Skip to content
Advertisement

why evaluateJavascript is getting iterated inside handler(Android)?

I want to evaluate a javascript in Webview Android as given below in the code. I want to evaluate it after 3 seconds. It works, it gets evaluated after 3 seconds but it(the code inside run()) keeps repeating after every 3 seconds in an infinite loop. I just want to evaluate it once after 3 seconds

JavaScript

MainActivity.java

JavaScript

activity_main.xml

JavaScript

Advertisement

Answer

calling evaluateJavascript will make onPageFinished to be called further, in which you are setting, again, your Handler

simplest way to avoid this is introducing some boolean which will be flagged after evaluating JS and prevent second and further calls

JavaScript

in callback

JavaScript

btw. you have probably some bug in flow for <19, only first JS will be loaded/executed

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement