Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:09:46+00:00 2026-06-11T14:09:46+00:00

I am using Webview and loadData method like this : try { htmlEncode =

  • 0

I am using Webview and loadData method like this :

                    try {   
                    htmlEncode = URLEncoder.encode(html, "UTF-8").replaceAll("\\+", " ");
                } catch (UnsupportedEncodingException e) {
                    htmlEncode = html;
                    e.printStackTrace();
                }           
                webView.loadData( htmlEncode,"text/html; charset=UTF-8", "UTF-8");

html is “html string”. Those of code is work fine in all android version except android 4.0.4. The webView don’t understand \n character. It can’t break to new line.
I and my partner searching for hours but can’t find any solution for this.
There are some reason we can’t use loadDataWithBaseURL() method.
Have you ever faced this problem ? or do you have any idea for us to find out what the wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:09:47+00:00Added an answer on June 11, 2026 at 2:09 pm

    I resoled my problem. I use webview by this way: Add webview to layout at runtime. So, when I use loadDataWithBaseURL() on Android 4.0.4. It can’t show html string so I used loadData() method instead. But when I used loadData() method some time the webview can’t show the content too, or have many problem with html string encode. But now I have solution.

            webView.postDelayed(new Runnable() {
            @Override
            public void run() {
                webView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", "UTF-8");
            }
        }, 100);
    

    I dont’ know why we have to delay a little time before calling loadDataWithBaseURL method.
    But as my guess, maybe because the webview need time to init before load the html string.
    Hope it help someone have this problem in future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Webview in an Android activity (say Activity B ) like this
I update the html in a webView using loadData() followed by a reload(). I
When using webview to show html pages, there will be several seconds of blank
I am using webview in Android. But strangely, sometimes even webview canGoBack method returns
webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl(http://officeofthemufti.sg/MaulidBooklet.pdf); I am using WebView try to loading pdf
I'm loading long pages into a WebView using loadData(), unfortunately after around 5 or
trouble loading html file from plist to webView using following code in FAQDetailViewController.m: -
I am displaying a text file that contains html code in a webview using
My app is using webview and loads a local html file in the assets/
I'm creating a sample webpage with button..this webpage am calling in Android using webview.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.