Vijay Prakash
Vijay Prakash

Reputation: 111

Webview content not loading all devices

I am loading data from server to device using webview. but its not loading in few device like Moto x and In some device loading but when go to another page from webview page and back to same page then webview content lost.this happening in Xperia z.Other devices samsung,Xiomi everthing working fine.

what is the problem and how can solve this problem so webview data render all device fine.

LOGCAT -:

[AdapterInputConnection.java:499] finishComposingText
 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
 D/cr_Ime: [AdapterInputConnection.java:145] Constructor called with outAttrs:  inputType=0xa1 imeOptions=0x12000000 privateImeOptions=null
 D/cr_Ime: actionLabel=null actionId=0
 D/cr_Ime: initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0
 D/cr_Ime: hintText=null label=null
 D/cr_Ime: packageName=com.org.AmarUjala.news fieldId=-1 fieldName=null
 D/cr_Ime: extras=null
 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText

here the Xml code

          <WebView
            android:id="@+id/storyText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:lineSpacingExtra="3dp"
            android:scrollbars="none"
            android:visibility="gone"
            android:textColor="@color/black" /> 

Here is the Java code:

int currentApi = android.os.Build.VERSION.SDK_INT;
mWebView.setInitialScale(0);
mWebView.requestFocus(View.FOCUS_DOWN);
mWebView.requestFocusFromTouch();
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setSupportZoom(false);
settings.setAppCacheEnabled(false);
settings.setSavePassword(false);
settings.setPluginState(WebSettings.PluginState.ON);
settings.setLoadsImagesAutomatically(true);
settings.setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadDataWithBaseURL("", ftext,"text/html",utf-8,"");              
mWebView.setVisibility(View.VISIBLE);

Upvotes: 1

Views: 1106

Answers (1)

user2054910
user2054910

Reputation:

There are some configurations that make no difference and perhaps you could remove them:

mWebView.setInitialScale(0); // This is 0 by default scale

settings.setAppCacheEnabled(false); // This is false by default

settings.setLoadsImagesAutomatically(true); //This is twice
settings.setLoadsImagesAutomatically(true); //This is twice

settings.setPluginState(WebSettings.PluginState.ON); // This is deprecated since API level 18

If those devices giving you trouble are running on API level 18+ the above line might be the issue.

Then it doesn't seem you are loading the content from a URL despite you are suing this method:

mWebView.loadDataWithBaseURL("", ftext,"text/html",utf-8,""); //The first parameter is empty and could lead to 'about:blank'

Use loadDataWithBaseURL if you are loading from a remote server and have a url, otherwise if you are loading from local then use other methods like: webview.loadData(summary, "text/html", null);

EDIT: Then based on your latest comments, I would save the Urls that the user navigates through in a collection and even save the scrollY in those specific devices. Then listen to the Back button and navigate through the save urls in those devices, reloading the page on each page if needed.

Upvotes: 0

Related Questions