我编写了一个在Webviews中显示html页面的应用程序,该页面在ViewPager中进行管理。一切正常,但是从一页滑动到另一页时,我遇到了一些ANR。 ANR数据转储显示主线程已通过ThreadedRenderer.nSyncAndDrawFrame()调用,该线程调用了一个 native 方法,该方法显然与Renderer线程进行通信,并等待该线程完成绘制 View 的过程。由于这两个代码都在执行 native 代码,因此很难弄清正在发生的事情,但是Renderer线程似乎从未向主线程发出恢复信号,从而导致了ANR。在ANR报告之前,logcat中没有任何内容表明任何问题。
有人对如何解决此问题有建议吗?我假设对ThreadedRenderer.nSyncAndDrawFrame()的调用与Webview关联,但是实际上我没有任何东西可以确认这一点。
从某种意义上说,该问题不是可重复的,如果我重新启动应用程序并导航到发生ANR时所显示的同一页面,则不会再次发生。设备是运行Android 5.1的Nexus 7。
主线程和渲染器线程的ANR stacktrace:
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 obj=0x73547000 self=0xb4827800
| sysTid=1248 nice=-6 cgrp=default sched=0/0 handle=0xb6fd6bec
| state=S schedstat=( 0 0 0 ) utm=6035 stm=1406 core=0 HZ=100
| stack=0xbe5a6000-0xbe5a8000 stackSize=8MB
| held mutexes=
kernel: (couldn't read /proc/self/task/1248/stack)
native: #00 pc 000133b8 /system/lib/libc.so (syscall+28)
native: #01 pc 00016a81 /system/lib/libc.so (__pthread_cond_timedwait_relative(pthread_cond_t*, pthread_mutex_t*, timespec const*)+56)
native: #02 pc 0003c73b /system/lib/libhwui.so (???)
native: #03 pc 0003c771 /system/lib/libhwui.so (???)
native: #04 pc 0083fd83 /data/dalvik-cache/arm/system@[email protected] (Java_android_view_ThreadedRenderer_nSyncAndDrawFrame__JJJF+134)
at android.view.ThreadedRenderer.nSyncAndDrawFrame(Native method)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:340)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2530)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke!(Native method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
"RenderThread" prio=5 tid=26 Native
| group="main" sCount=1 dsCount=0 obj=0x12c07820 self=0xa1c30800
| sysTid=1303 nice=-4 cgrp=default sched=0/0 handle=0xa1c44c00
| state=S schedstat=( 0 0 0 ) utm=8314 stm=1817 core=0 HZ=100
| stack=0xa0cc2000-0xa0cc4000 stackSize=1012KB
| held mutexes=
kernel: (couldn't read /proc/self/task/1303/stack)
native: #00 pc 000133b8 /system/lib/libc.so (syscall+28)
native: #01 pc 0001741b /system/lib/libc.so (__futex_wait_ex+42)
native: #02 pc 00017761 /system/lib/libc.so (pthread_mutex_lock+230)
native: #03 pc 0001d767 /system/vendor/lib/libgsl.so (os_mutex_lock+6)
native: #04 pc 0001ea88 /system/vendor/lib/egl/libEGL_adreno.so (egliDoDestroyEGLImage+180)
native: #05 pc 0008698d /system/vendor/lib/egl/libGLESv2_adreno.so (rb_image_try_release+32)
native: #06 pc 00086acf /system/vendor/lib/egl/libGLESv2_adreno.so (rb_destroy_resource_updates_pure+136)
native: #07 pc 00085491 /system/vendor/lib/egl/libGLESv2_adreno.so (rb_perform_resolve+276)
native: #08 pc 00085761 /system/vendor/lib/egl/libGLESv2_adreno.so (rb_resolve+464)
native: #09 pc 0008a891 /system/vendor/lib/egl/libGLESv2_adreno.so (rb_surface_swap+228)
native: #10 pc 0006af89 /system/vendor/lib/egl/libGLESv2_adreno.so (gl2_surface_swap+76)
native: #11 pc 0005d12b /system/vendor/lib/egl/libGLESv2_adreno.so (oglSwapBuffer+194)
native: #12 pc 00013ddc /system/vendor/lib/egl/libEGL_adreno.so (qeglDrvAPI_eglSwapBuffers+1776)
native: #13 pc 00007b60 /system/vendor/lib/egl/libEGL_adreno.so (eglSwapBuffers+16)
native: #14 pc 0001237f /system/lib/libEGL.so (eglSwapBuffers+290)
native: #15 pc 0003d291 /system/lib/libhwui.so (???)
native: #16 pc 0003bd05 /system/lib/libhwui.so (???)
native: #17 pc 0003beb5 /system/lib/libhwui.so (???)
native: #18 pc 0003caed /system/lib/libhwui.so (???)
native: #19 pc 0003e743 /system/lib/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+66)
native: #20 pc 000104d5 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+112)
native: #21 pc 0005f839 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+72)
native: #22 pc 00010045 /system/lib/libutils.so (???)
native: #23 pc 00016baf /system/lib/libc.so (__pthread_start(void*)+30)
native: #24 pc 00014af3 /system/lib/libc.so (__start_thread+6)
最佳答案
它可能是Android 7.0 WebView上的错误,您可以通过以下两种方法对其进行修复:
1,webView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
2,android:hardwareAccelerated =“false”
关于android - Webview导致ANR,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30828802/