0

I'm using webView.loadDataWithBaseURL(null, html, null, "utf-8", null); method to refresh my WebView, but it is not refreshing the UI the second time. It works well the first time.

Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
SriramTej
  • 21
  • 5
  • Please post the code that you have implemented for doing this, so that we can properly point out your mistakes and help you fix them. – Salman Khakwani Jun 05 '14 at 05:19
  • `webView.loadUrl( "javascript:window.location.reload( true )" );` and make sure you have this line of code `webView.getSettings().setJavaScriptEnabled(true);` – Aniruddha Jun 05 '14 at 05:42
  • I am trying to post the code but the site is warning me with the message "Users with less than 10 reputation can't answer their own question for 8 hours after asking" – SriramTej Jun 05 '14 at 05:58
  • Hi Salman and in the comment section i could not post the answer as it is too long – SriramTej Jun 05 '14 at 05:59
  • I have the line of code webView.getSettings().setJavaScriptEnabled(true); but still no use – SriramTej Jun 05 '14 at 06:14
  • @SriramTej don't answer to your question just click on the edit option between the share and flag options below the two Tags of android and android-webview and there post your code. – Abid Khan Jun 05 '14 at 06:17

1 Answers1

0

How would you like to refresh your Webview? Depends on your project requirements. Try it if you want it at OnCLickListener. If you want your data from assets or any directory to a Webview you can use loadDataWithBaseURL() with appropriate parameters.

You can load image via Webview using the following code

String html;
html = html.concat("<html><head><title>TITLE!!!</title></head>");
html = html.concat("<body><h1>Image?</h1><img src="icon.png" /></body></html>");
webview . loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "UTF-8", null);

for more details try it

Community
  • 1
  • 1
user3384985
  • 2,975
  • 6
  • 26
  • 42
  • Actually i am trying to post some post data to server everytime user clicks a button with new values and will load the webpage with the response data i have received from the server and in this context it is a image source. – SriramTej Jun 05 '14 at 06:02
  • it would be clear for me if i can see your code. check my updated answer – user3384985 Jun 05 '14 at 06:34
  • I tried your above solution but no use user3384985 and i am trying to post the code here – SriramTej Jun 05 '14 at 06:46
  • This is my Asynctask which i have been calling in onCreate() method – SriramTej Jun 05 '14 at 06:46
  • private class DownloadFilesTask extends AsyncTask { protected void onPostExecute(String result) { if (result != null) { webview.loadDataWithBaseURL(url, result, "text/html", "UTF-8",null); }} @Override protected String doInBackground(String... params) { // some http post request data here which finally throws some response return stringBuilder.toString(); return null;}} – SriramTej Jun 05 '14 at 06:48
  • have you formatted your code(result) to html before webview.loadDataWithBaseURL(url, result, "text/html", "UTF-8", null); execution in onPostExecute(String result)? – user3384985 Jun 05 '14 at 06:56
  • it is already formatted . I mean the result itself is coming in HTML format – SriramTej Jun 05 '14 at 07:06
  • The above problem has been solved with the below piece of code @Override public void onDestroy() { if (webview != null) { webview.destroy(); webview = null; } super.onDestroy(); } I don't know the exact reason behind this but above code played as a trick. – SriramTej Jun 25 '14 at 06:13