当前位置:网站首页>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 需要做空判断.
边栏推荐
- "Configuration" is a double-edged sword, it will take you to understand various configuration methods
- 【LeetCode刷题】-数之和专题(待补充更多题目)
- RAID磁盘阵列
- The 2022 EdgeX China Challenge will be grandly opened on August 3
- Domain Driven Design - MDD
- ARM Mailbox
- Leetcode brushing questions - 22. Bracket generation
- mysql树状结构查询问题
- Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
- 如何模拟后台API调用场景,很细!
猜你喜欢

树表的查找
![[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?](/img/81/2dcb61fd6c30f726804c73cf2b3384.jpg)
[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?

DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)

没有对象的程序员如何过七夕

Leetcode brushing questions - 22. Bracket generation

【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗

从零到一快速学会三子棋

Pisanix v0.2.0 released | Added support for dynamic read-write separation
![[Word] #() error occurs after Word formula is exported to PDF](/img/6a/168ded19d22826b6af974907f480fb.png)
[Word] #() error occurs after Word formula is exported to PDF

常见的硬件延迟
随机推荐
[Endnote] Word inserts a custom form of Endnote document format
转:查尔斯·汉迪:你是谁,比你做什么更重要
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
source program in assembly language
leetcode-另一棵树的子树
MySQL3
PHP技能评测
Oracle encapsulates restful interfaces into views
std::string::find 返回值的坑
C语言实现简单猜数字游戏
.Net C# 控制台 使用 Win32 API 创建一个窗口
如何看待自己的羞愧感
如何逐步执行数据风险评估
树形查找(二叉查找树)
Opening - Open a new .NET modern application development experience
leetcode 15
海量服务实例动态化管理
Programmer's list of sheep counting when insomnia | Daily anecdote
Tree search (bintree)
意识形态的机制