当前位置:网站首页>View handler 踩坑记录
View handler 踩坑记录
2022-08-05 02:24:00 【吃饱很舒服】
问题
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 需要做空判断.
边栏推荐
猜你喜欢
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
nodeJs--encapsulate routing
DAY23: Command Execution & Code Execution Vulnerability
树表的查找
How to simply implement the quantization and compression of the model based on the OpenVINO POT tool
Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?
迁移学习——Distant Domain Transfer Learning
LeetCode uses the minimum cost to climb the stairs----dp problem
C语言日记 9 if的3种语句
C language implements a simple number guessing game
随机推荐
LeetCode使用最小花费爬楼梯----dp问题
Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
学习笔记-----左偏树
02 【开发服务器 资源模块】
Transfer Learning - Joint Geometrical and Statistical Alignment for Visual Domain Adaptation
使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
继承关系下构造方法的访问特点
常见的硬件延迟
Pisanix v0.2.0 released | Added support for dynamic read-write separation
fragment可见性判断
nodeJs--封装路由
[ROS](10)ROS通信 —— 服务(Service)通信
高数_复习_第1章:函数、极限、连续
直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计
【OpenCV 图像处理2】:OpenCV 基础知识
《.NET物联网从零开始》系列
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
力扣-相同的树