Recently, I've been tackling an issue involving making a synchronous call to JavaScript within a WebView
, with the aim of retrieving a return value. However, pinpointing why this setup is not functioning properly has proven to be quite challenging for me. It appears that the WebView
's thread is getting blocked while the main thread awaits a response from it - a situation that shouldn't occur as the WebView
operates on a separate thread.
In order to shed some light on this problem, I have put together a concise sample code snippet:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"/>
</LinearLayout>
...
(Further details provided in the original text.)