Created
October 30, 2017 07:21
-
-
Save yimun/0307f892fd9146b666b3f2bd862cef47 to your computer and use it in GitHub Desktop.
post runnable when thread idle
This file contains hidden or 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
| private void postThreadIdleRunnable(Looper looper, final Runnable runnable) { | |
| try { | |
| Field field = Looper.class.getDeclaredField("mQueue"); | |
| field.setAccessible(true); | |
| MessageQueue queue = (MessageQueue) field.get(looper); | |
| queue.addIdleHandler(new MessageQueue.IdleHandler() { | |
| @Override | |
| public boolean queueIdle() { | |
| runnable.run(); | |
| return true; | |
| } | |
| }); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment