首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >视图绑定返回空

视图绑定返回空
EN

Stack Overflow用户
提问于 2022-03-01 14:19:37
回答 1查看 888关注 0票数 1

在底部工作表对话框中

代码语言:javascript
复制
class XBottomSheet () : BottomSheetDialogFragment() {

    private var _binding: XBottomSheetBinding? = null
    private val binding get() = _binding!!
    private var handlerRunner: Runnable? = null
    private val handler = Handler(Looper.getMainLooper())

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = XBottomSheetBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        handlerRunner = Runnable {
            binding.tvTimeOffer.text = "text"
       }
       
       handler.postDelayed(handlerRunner!!, 1)
    }


    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null

        handlerRunner?.apply {
            handler.removeCallbacks(this)
        }
    }
}

在某些手机中,Firebase carashlytics会记录private val binding get() = _binding!! 非致命异常:private val binding get() = _binding!!

在某个时候,在设置_binding = null之后,处理程序可以在删除它之前调用runnable吗??

我不知道为什么!

EN

回答 1

Stack Overflow用户

发布于 2022-03-01 14:37:48

在绑定获得null之前删除处理程序回调

代码语言:javascript
复制
override fun onDestroyView() {
        super.onDestroyView()
        handler?.removeCallbacks(this)
        _binding = null
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71309910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档