Android webview loading data performance very slow -


hi working on 1 application, in using android webview. whenever launch webview activity, loading data in string html format test.txt file. test.txt file contains 2.5 mb data, after loading test.txt file, if slide screen end read data , press back. subsequent launch of webview activity taking more time render data. in first launch of webview taking minimal time. not getting error/exception/crash in between launching activity.

i using android api level 18 , above

note: did lot of research on issue. tried solution android webview slow , android webview performance no use.

i can't make android:hardwareaccelerated="true" <-- why because has lot of side effects (still used one, no changes found on issue).

i can't use webview.getsettings().setrenderpriority(renderpriority.high);

setrenderpriority() --> method deprecated in api level 18. not recommended adjust thread priorities, , not supported in future versions.

my dataloader.java class

public class dataloader extends activity {      private webview webview = null;     // progress dialog     private progressdialog progressdialog;      string datacontent = null;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          setcontentview(r.layout.web_view);         webview = (webview)findviewbyid(r.id.text);          // loading webview in background thread         new loadwebview().execute();     }      class loadwebview extends asynctask<string, string, string> {          @override         protected void onpreexecute() {             super.onpreexecute();             progressdialog = new progressdialog(dataloader.this);             progressdialog.settitle("loading...");             progressdialog.setmessage("please wait.");             progressdialog.setcancelable(false);             progressdialog.setindeterminate(true);             progressdialog.show();         }          protected string doinbackground(string... args) {             // assetfilereader read txt file , return data in form of string             datacontent = assetfilereader.read(getapplicationcontext(), "test.txt");              return null;         }          protected void onpostexecute(string str) {             // dismiss dialog             progressdialog.dismiss();              if (datacontent != null) {                 // updating ui background thread                 runonuithread(new runnable() {                     public void run() {                          websettings s = webview.getsettings();                         s.setusewideviewport(true);                         s.setsupportzoom(true);                         s.setbuiltinzoomcontrols(true);                         s.setdisplayzoomcontrols(false);                         s.setjavascriptenabled(true);                         webview.loaddata(datacontent, "text/html", "utf-8");                     }                 });             }         }     }      @override     public void ondestroy() {         super.ondestroy();         webview.clearcache(true);         webview.clearhistory();     } } 

my web_view.xml file

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <webview         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@+id/text">     </webview>  </linearlayout> 

please let me know if have work around on issue.

i think following works best:

if (build.version.sdk_int >= 19) {     webview.setlayertype(view.layer_type_hardware, null); }        else {     webview.setlayertype(view.layer_type_software, null); } 

android 19 has chromium engine webview. guess works better hardware acceleration.

for more info android 4.4 kitkat, browser , chrome webview

hardware acceleration do's trick.you can use in different levels in application.

application level

<application android:hardwareaccelerated="true" ...> 

activity level

<application android:hardwareaccelerated="true">     <activity ... />     <activity android:hardwareaccelerated="false" /> </application> 

window level

getwindow().setflags(     windowmanager.layoutparams.flag_hardware_accelerated,     windowmanager.layoutparams.flag_hardware_accelerated); 

view level

myview.setlayertype(view.layer_type_software, null); 

but mentioned in question can elaborate side effects ?


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -