Last active
November 25, 2016 07:28
-
-
Save linroid/471f7de83c268f8e5a28bd3aa3a98a3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Handler; | |
import android.os.Looper; | |
/** | |
* @author linroid <linroid@gmail.com> | |
* @since 25/11/2016 | |
*/ | |
public class SafetyUtils { | |
public static void removeCallbacks(final Handler handler, final Runnable callback) { | |
if (handler.getLooper() == Looper.myLooper()) { | |
handler.removeCallbacks(callback); | |
} else { | |
handler.post(new Runnable() { | |
@Override | |
public void run() { | |
handler.removeCallbacks(callback); | |
} | |
}); | |
} | |
} | |
public static void removeMessages(final Handler handler, final int what) { | |
removeMessages(handler, what, null); | |
} | |
public static void removeMessages(final Handler handler, final int what, final Object obj) { | |
if (handler.getLooper() == Looper.myLooper()) { | |
handler.removeMessages(what, obj); | |
} else { | |
handler.post(new Runnable() { | |
@Override | |
public void run() { | |
handler.removeMessages(what, obj); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment