在底部工作表对话框中
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吗??
我不知道为什么!
发布于 2022-03-01 14:37:48
在绑定获得null之前删除处理程序回调
override fun onDestroyView() {
super.onDestroyView()
handler?.removeCallbacks(this)
_binding = null
}https://stackoverflow.com/questions/71309910
复制相似问题