test Thread.sleep

This commit is contained in:
Alexander Mahr 2024-10-09 16:13:30 +02:00
parent 1c4c210091
commit 51734be9f8
2 changed files with 8 additions and 3 deletions

View file

@ -12,7 +12,8 @@ import android.webkit.WebView;
import android.webkit.*; import android.webkit.*;
import android.view.ViewGroup.*; import android.view.ViewGroup.*;
import android.util.Base64; import android.util.Base64;
//import java.util.Timer; import java.lang.Thread;
public class ExampleApp extends Activity { public class ExampleApp extends Activity {
@Override @Override
@ -43,7 +44,11 @@ public class ExampleApp extends Activity {
// java.util.TimerTask() { // java.util.TimerTask() {
// @Override // @Override
// public void run() { // public void run() {
// myWebView.evaluateJavascript("document.body.innerHTML='all is lost';",null); // this actually blocks all of the webview
try {
Thread.sleep(3000);
} catch (Exception e) { }
myWebView.evaluateJavascript("document.body.innerHTML='all is lost';",null);
// // this code will be executed after 2 seconds // // this code will be executed after 2 seconds
// } // }
// , 2000); // , 2000);

View file

@ -33,7 +33,7 @@ public class MyJavascriptInterface {
// } // }
@JavascriptInterface @JavascriptInterface
public String toString() { public String toString() {
this.webview.evaluateJavascript("(setTimeout(()=>{document.body.innerHTML='all gone';},2000)()",null); // this.webview.evaluateJavascript("(setTimeout(()=>{document.body.innerHTML='all gone';},2000)()",null);
return "injectedobject"; return "injectedobject";
} }
} }