如何从处理程序中删除所有回调

如何从处理程序中删除所有回调

本文介绍了如何从处理程序中删除所有回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自我的子活动的,由主要的。子类使用此处理程序来一些Runnables,我不能管理它们。现在,在onStop事件中,我需要在完成活动之前删除它们(不知何故,我调用finish(),但它仍然一次又一次调用)。是否还有从处理程序中删除所有回调?

I have a handler from my sub-Activity that was called by the main Activity. This handler is used by sub-classes to postDelay some Runnables, and I can't manage them. Now, in onStop event, I need to remove them before finish the activity (somehow I called finish(), but it still call again and again). Is there anyway to remove all callbacks from a Handler?

谢谢。

推荐答案

在我的经验中,调用这个工作太棒了!

In my experience calling this worked great!

handler.removeCallbacksAndMessages(null);

在removeCallbacksAndMessages的文档中,它表示...

In the docs for removeCallbacksAndMessages it says...

这篇关于如何从处理程序中删除所有回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:48