In my experience, I have found that running a JavaScript function in a webview requires loading it using loadUrl(). Everything seems to work fine in my program when I use loadUrl to call the JavaScript. However, instead of executing the JavaScript on the same page, loadUrl("javascript:function()") causes the previous page to disappear and the JavaScript "function()" is executed on a completely new blank page.
For example, I attempted to automatically fill out a form using the command:
view.loadUrl("javascript:document.getElementById('password').value = 'my_passoword'");
What happens is that the page containing the ID-'password' disappears and a new blank page is created with only 'my_password' displayed.
The question remains: where is the problem occurring?