Pergunta

I am working on an jQuery Mobile application which uses HTML pages for UI There are some JS function through which i call some native functions. There are some popups and dialogs with input fields, but when i open some dialog or popup in html the logCat gives me this warning

W/webview_proxy(8104): java.lang.Throwable: Warning: A WebView method was called on thread
'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of
WebView may not support use on other threads.

and while entering values in these input fields page and keyboard starts blinking. that's how i am calling theses native functions

JS Function

function SettingMethod()
{
activity.setSettings();
}

Android Method

@JavascriptInterface
public void setSettings() {
    SharedPreferences settings = PreferenceManager
            .getDefaultSharedPreferences(MainActivity.this);
    final String webServiceURL = settings.getString("URL", "");
    final String InputFolder = settings.getString("INPUTFOLDER", "");
    final String OutPutFolder = settings.getString("OUTPUTFOLDER", "");

  index.loadUrl("javascript:setSettings('" + webServiceURL + "','"
                    + InputFolder + "','" + OutPutFolder + "')");
  }

how can i remove this lag ?

Foi útil?

Solução

Problem solved by using

runOnUiThread(new Runnable() {
     public void run() {
     index.loadUrl("javascript:setSettings('" + webServiceURL + "','"
                    + InputFolder + "','" + OutPutFolder + "')");
                    }
                });
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top