0

I have a webview with HTML webpage which is downloaded from server and i populate dynamic data and add rows of information to this webpage. I have used the following code on that webpage to enable javascript:

    class JSClass {
    Context jsContext;
    JSClass(Context c){
        jsContext = c;
}
public void getHTMLContent(String info)
{
    Log.i(TAG, "Info: "+info);
}
}

WebView webview = (WebView) findViewById(R.id.webView);
webview.loadDataWithBaseURL("", htmlcontent, "text/html", "utf-8", "");
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.addJavascriptInterface(new JSClass(this), "Android");
webview.loadUrl("javascript:"+
    "var rows = document.getElementsByClassName('info');"+
    "if(rows !== null){"+
    "for(var i=0;i<rows.length;i++){"+
    "rows[i].onclick = function(){"+
    "var workId = 0;"+
    "workId = parseInt(this.cells[0].innerHTML);"+
    "window.Android.getHTMLContent(workId);"+
    "}}}"
);

when i click on any row, i cal an intent to download images from the server depending on the row data. It works fine on first click, but the second time i click, the application closes without any error. I don't understand the reason. Please help. Thanks in advance

4
  • 2
    Does "without any error" means that even in the LogCat you don't have a clue? Commented Jun 28, 2013 at 13:28
  • To get JS messages (errors and alike) into the Logcat override the ChartWebChromeClient#onConsoleMessage message and print out each message to LogCat. Note that the API was introduced in FROYO so be sure to defend against that if you are running sub v2.2 Commented Jun 28, 2013 at 15:35
  • @OceanLife: yes!there are no error messages in the logcat also. I am overriding the WebChromeClient's onConsoleMessage. actually it runs smooth on emulator for 100 clicks. This prblm s faced only on droid devices Commented Jun 29, 2013 at 5:34
  • I have faced many a strange behaviour when reviewing the JS activities in my app on skinned devices. It's more than likely that the 'droid range you are testing on has replaced the WebKit bundled with the core OS. Search for specific issues with your device relating to WebViews and the backing WebKit to progress... Commented Jun 29, 2013 at 12:57

2 Answers 2

0

I think you need to use loadDataWithBaseURL again instead of just loadUrl.

See this link. There is a section explaining loadData that says:

Note that JavaScript's same origin policy means that script running in a page loaded using this method will be unable to access content loaded using any scheme other than 'data', including 'http(s)'. To avoid this restriction, use loadDataWithBaseURL() with an appropriate base URL.

Sign up to request clarification or add additional context in comments.

1 Comment

i cannot do that. The existing dynamic data gets replaced by javascript
0

FINALLY!! fixed it.. the adapter was holding previously downloaded images as well as the images downloaded during second click and i don't understand why the application was closing without giving any memory leaks as well.. anyways its working fine now after using

adapter.clear();

or re-initializing the adapter to null after all the image thumbs are downloaded(i do not know if this is very efficient). After the adapter is cleared, use

adapter.notifyDataSetChanged();

1 Comment

my next task is to implement pinch zoom for images. After showing image thumbs in gridview, onClick of gridView,i cal an intent to display a larger image in next activity. I have used ImageSwitcher and ImageView to accomplish Fling Gestures to load next image. I do not understand how to zoom the images in my current situation. any suggestions?? Please help...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.