I'm developing an app that loads a HTML string into a WebBrowser, but when I call the LoadFromString methods from WebBrowser, it throws a RuntimeException with the message:
java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'Thread-2'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {c7ba400} called on null, FYI main Looper is Looper (main, tid 2) {c7ba400})
The HTML is stored in a file and loaded into a string just for test reasons, the final app will get the string from a DataSnap and show it using WebBrowser.
This is the code:
procedure LoadString;
var
htmlContent: String;
filePath: String;
dbpath: String;
begin
filePath := TPath.Combine(TPath.GetDocumentsPath, 'index.html');
htmlContent := TFile.ReadAllText(filePath);
WebBrowser1.LoadFromStrings(htmlContent, 'about:blank');
btnSearch.Visible := False;
TabControl1.GotoVisibleTab(tbResult.Index);
end;
I'm not using thread in this app.
If relevant, I'm using Delphi 10.1 Berlin and testing in a Moto G5 with Android 9.
The WebBroser method needs to run in the UI Thread, so like Dalija Prasnikar comment said, I moved the call to CallInUiThread and everything is working now.