java - ART kills WebView before loading finished -


i'm trying retrieve html website uses javascript. method goes follows:

  • create headless webview (without view defined in xml) , enable js.
  • create javascriptinterface method called when loading finishes.
  • override onpagefinished method of webclientview provide. code here injects javascript call method defined in javascriptinterface, passing html contents of page parameter.

what's interesting is, code works, inconsistently. 1 time work intended, , next time nothing happen. getting sorts of weird logcat messages, 1 of suspected bad sign: w/art: attempt remove non-jni local reference, dumping thread. today idea popped mind: maybe webview gets killed because runtime environment optimizations (and webview has no xml view object linked it)?

and so, decided try creating webview in xml , use same code instead of creating 1 in code. right code works consistently, every time run it, , no longer receive thread dumping log messages. see page finishes loading, code executed.

do note, noticed specific website i'm referencing takes relatively long time load (as long few seconds), , onpagefinished gets called more once, delivering html unprocessed js unless last call.

so, questions is: there way prevent art dumping thread when using headless version (or other workaround)? thought of keeping webview defined in xml, , setting visibility false, seems resource-heavy solution.

i'm working android emulator (although got same results using physical device well), target api 24, minimum api 15.

relevant code:

private void fetchhtml(view view, string url) {     class jsinterface{         @javascriptinterface         public void processhtml(string html){             log.d(log_tag, html); // bit of code gets executed, , not         }     }     //final webview webview = (webview) view.findviewbyid(r.id.webview);     final webview webview = new webview(context);     websettings settings = webview.getsettings();     settings.setdomstorageenabled(true);     webview.addjavascriptinterface(new jsinterface(), "android");     webview.setwebchromeclient(new webchromeclient());     webview.setwebviewclient(new webviewclient(){         @override         public void onpagefinished(webview view, string url) {             super.onpagefinished(view, url);             if(webview.getprogress() == 100){                 webview.loadurl("javascript:window.android.processhtml("                         + "'<head>'+document.getelementsbytagname('html')[0].innerhtml+'</head>');");             }         }     });      settings.setjavascriptenabled(true);     webview.loadurl(url); } 

relevant logcat when not executed properly:

07-15 17:16:27.616 17779-17779/com.michaelsvit.kolnoa w/system: classloader referenced unknown path: /data/app/com.michaelsvit.kolnoa-2/lib/x86 07-15 17:16:28.214 17779-17779/com.michaelsvit.kolnoa w/system: classloader referenced unknown path: /data/app/com.michaelsvit.kolnoa-2/lib/x86 07-15 17:16:28.267 17779-17779/com.michaelsvit.kolnoa w/art: before android 4.1, method android.graphics.porterduffcolorfilter android.support.graphics.drawable.vectordrawablecompat.updatetintfilter(android.graphics.porterduffcolorfilter, android.content.res.colorstatelist, android.graphics.porterduff$mode) have incorrectly overridden package-private method in android.graphics.drawable.drawable 07-15 17:16:28.448 17779-17779/com.michaelsvit.kolnoa i/webviewfactory: loading com.android.webview version 44.0.2403.119 (code 246011910) 07-15 17:16:28.456 17779-17779/com.michaelsvit.kolnoa w/system: classloader referenced unknown path: /system/app/webview/lib/x86 07-15 17:16:28.465 17779-17779/com.michaelsvit.kolnoa i/libraryloader: time load native libraries: 3 ms (timestamps 8656-8659) 07-15 17:16:28.465 17779-17779/com.michaelsvit.kolnoa i/libraryloader: expected native library version number "",actual native library version number "" 07-15 17:16:28.470 17779-17779/com.michaelsvit.kolnoa v/webviewchromiumfactoryprovider: binding chromium main looper looper (main, tid 1) {c4bffce} 07-15 17:16:28.470 17779-17779/com.michaelsvit.kolnoa i/libraryloader: expected native library version number "",actual native library version number "" 07-15 17:16:28.470 17779-17779/com.michaelsvit.kolnoa i/chromium: [info:library_loader_hooks.cc(120)] chromium logging enabled: level = 0, default verbosity = 0 07-15 17:16:28.476 17779-17779/com.michaelsvit.kolnoa i/browserstartupcontroller: initializing chromium process, singleprocess=true 07-15 17:16:28.479 17779-17779/com.michaelsvit.kolnoa w/art: attempt remove non-jni local reference, dumping thread 07-15 17:16:28.479 17779-17779/com.michaelsvit.kolnoa e/sysutils: applicationcontext null in applicationstatus 07-15 17:16:28.484 17779-17779/com.michaelsvit.kolnoa w/chromium: [warning:resource_bundle.cc(285)] locale_file_path.empty() 07-15 17:16:28.487 17779-17779/com.michaelsvit.kolnoa e/libegl: validate_display:255 error 3008 (egl_bad_display) 07-15 17:16:28.487 17779-17779/com.michaelsvit.kolnoa e/libegl: validate_display:255 error 3008 (egl_bad_display)                                                                  [ 07-15 17:16:28.488 17779:17779 d/         ]                                                                 hostconnection::get() new host connection established 0xac3edff0, tid 17779 07-15 17:16:28.525 17779-17779/com.michaelsvit.kolnoa e/eglcodeccommon: glutilsparamsize: unknow param 0x00008d57 07-15 17:16:28.552 17779-17779/com.michaelsvit.kolnoa e/datareductionproxysettinglistener: no drp key due exception:java.lang.classnotfoundexception: com.android.webview.chromium.drp 07-15 17:16:28.568 17779-17831/com.michaelsvit.kolnoa w/audiomanagerandroid: requires bluetooth permission 07-15 17:16:28.578 17779-17779/com.michaelsvit.kolnoa w/art: attempt remove non-jni local reference, dumping thread 07-15 17:16:28.582 17779-17779/com.michaelsvit.kolnoa w/awcontents: ondetachedfromwindow called when detached. ignoring 07-15 17:16:28.584 17779-17779/com.michaelsvit.kolnoa w/art: attempt remove non-jni local reference, dumping thread 07-15 17:16:28.585 17779-17779/com.michaelsvit.kolnoa w/awcontents: ondetachedfromwindow called when detached. ignoring 07-15 17:16:28.587 17779-17779/com.michaelsvit.kolnoa w/art: attempt remove non-jni local reference, dumping thread 07-15 17:16:28.587 17779-17779/com.michaelsvit.kolnoa w/art: attempt remove non-jni local reference, dumping thread 07-15 17:16:28.620 17779-17841/com.michaelsvit.kolnoa d/openglrenderer: use egl_swap_behavior_preserved: true 07-15 17:16:28.639 17779-17829/com.michaelsvit.kolnoa w/chromium: [warning:data_reduction_proxy_config.cc(423)] spdy proxy off @ startup 07-15 17:16:28.740 17779-17841/com.michaelsvit.kolnoa i/openglrenderer: initialized egl, version 1.4                                                                          [ 07-15 17:16:28.741 17779:17841 d/         ]                                                                         hostconnection::get() new host connection established 0xa0a5f8d0, tid 17841 07-15 17:16:28.782 17779-17841/com.michaelsvit.kolnoa w/egl_emulation: eglsurfaceattrib not implemented 07-15 17:16:28.782 17779-17841/com.michaelsvit.kolnoa w/openglrenderer: failed set egl_swap_behavior on surface 0xaa3d9180, error=egl_success                                                                          [ 07-15 17:16:28.815 17779:17850 d/         ]                                                                         hostconnection::get() new host connection established 0xa0c82c80, tid 17850 07-15 17:16:29.166 17779-17779/com.michaelsvit.kolnoa w/bindingmanager: cannot call determinedvisibility() - never saw connection pid: 17779 07-15 17:16:29.279 17779-17779/com.michaelsvit.kolnoa d/moviegridfragment:  07-15 17:16:29.768 17779-17779/com.michaelsvit.kolnoa w/bindingmanager: cannot call determinedvisibility() - never saw connection pid: 17779 07-15 17:16:30.894 17779-17779/com.michaelsvit.kolnoa i/chromium: [info:console(2)] "uncaught typeerror: cannot read property 'length' of undefined", source:  (2) 07-15 17:16:31.196 17779-17829/com.michaelsvit.kolnoa w/chromium: [warning:spdy_session.cc(2527)] received window_update invalid stream 1 

following idea proposed, kept xml-defined webview (with visibility set "gone") , used instead of creating @ runtime. haven't had issues since.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -