java.lang.IllegalStateException: Unable to create layer for X — when using hardware layers

ε祈祈猫儿з 提交于 2020-05-27 00:19:37

问题


I'm using hardware layers on a custom view for better performance when animating its alpha. Seeing this crash on my crash reporter:

Fatal Exception: java.lang.IllegalStateException: Unable to create layer for X
   at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
   at android.os.MessageQueue.next(MessageQueue.java:323)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5585)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

My current workaround is waiting for this to happen, then storing a boolean for "device doesn't support hardware layers", and continuing with the crash that one time... then next time falling back to a simpler animation instead.

Given that this happens asynchronously, I can't really try-catch. Does anyone know of a way to check beforehand whether the operation would succeed, in order to use the fallback directly and not having to crash on the user even once?

Thanks!


回答1:


Looks similar to https://issuetracker.google.com/issues/118714995. See if this helps.

Setting your parent view with View#forceHasOverlappingRendering(false).



来源:https://stackoverflow.com/questions/47253835/java-lang-illegalstateexception-unable-to-create-layer-for-x-when-using-hard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!