问题
view 执行 onDetachedFromWindow 后, view 实例还会存在, 但 view 中的 handler 会被置空, 当使用到 view 中的 handler 时, 需要做出空判断
原理
view 的 handler 通过 view.getHandler() 获取, 下图可见, handler 从 mAttachInfo 中获取, mAttachInfo 在 dispatchAttachedToWindow 中赋值, 在 dispatchDetachedFromWindow 中置空, 其中 dispatchAttachedToWindow 会调用 view 的 onAttachedToWindow, dispatchDetachedFromWindow 中会调用 view 的 onDetachedFromWindow.
结论
所以首先我们要在 view 的 onDetachedFromWindow 中 移除 handler 的 runnable 或 callback, 在其他使用 handler 的时机, handler 需要做空判断.