问题
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