Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView does not render local HTML page on app launch in Android 4.0.x Ice Cream Sandwich

I know this question has been asked in different formats on this forum, but none of the answers - accepted or otherwise that I found there have helped me so far.

I am working on a hybrid app that uses native android, HTML and Adboe's Flex SDK (without any frameworks like PhoneGap etc., straightforward code using Android's own WebView).

Here's the issue I am facing:

When the app is launched, at first the activity "AppEntry" for the flex sdk is triggered, it is a blank activity which simply sets the context and initial setups for the flex SDK. Next, the native MainActivity is launched which uses a WebView to load the HTML project. On Android 4.0.x (ICS), the webview turns out to be blank(white) even thought the URL is loaded (onPageFinished() is called successfully for the URL in question). This happens the first time the app is installed and launched, after stopping the app (by removing it from the recent apps bar), the page is loaded as expected. Repeated re-launching like this reproduces the issue sometimes but with unpredictable frequency.

Some things for consideration:

  1. Due to flex sdk constraints, these HTML files cannot be stored directly in the '/assets' folder but a directory structure contained within the assets folder.

  2. Issue occurs only on Ice Cream Sandwich (known issue I guess)!

Stuff that I have tried already:

  1. Hardware acceleration is off (on/off does not matter, tested with both)

2.

WebSettings settings = webView.getSettings();        
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setSupportMultipleWindows(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLoadsImagesAutomatically(true);
        settings.setDomStorageEnabled(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        settings.setSaveFormData(true);
        settings.setAllowFileAccess(true);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
            settings.setAllowContentAccess(true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                settings.setAllowFileAccessFromFileURLs(true);
                settings.setAllowUniversalAccessFromFileURLs(true);
            }
        }
        settings.setAppCacheEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLoadsImagesAutomatically(true);
        boolean enableZoom = true;
        settings.setBuiltInZoomControls(enableZoom);
        settings.setSupportZoom(enableZoom);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
            initializePluginAPI(webView);
        }
        settings.setDatabaseEnabled(true);

The issue is killing my app's review comments on the play store. Any help or insight would be appreciated.

like image 427
devanshu_kaushik Avatar asked Aug 28 '15 09:08

devanshu_kaushik


1 Answers

the webview turns out to be blank(white) even thought the URL is loaded (onPageFinished() is called successfully for the URL in question).

I solved it by use mWebView.post()

like image 143
joe Avatar answered Sep 25 '22 08:09

joe