// 仔细阅读下面这段注释!!! // Postpone the runnable until we know on which thread it needs to run. // Assume that the runnable will be successfully placed after attach. getRunQueue().post(action); return true; }
public class HandlerActionQueue { private HandlerAction[] mActions; private int mCount;
public void post(Runnable action) { postDelayed(action, 0); }
public void postDelayed(Runnable action, long delayMillis) { final HandlerAction handlerAction = new HandlerAction(action, delayMillis);
synchronized (this) { if (mActiOns== null) { mActiOns= new HandlerAction[4]; } mActiOns= GrowingArrayUtils.append(mActions, mCount, handlerAction); mCount++; } }
public void executeActions(Handler handler) { synchronized (this) { final HandlerAction[] actiOns= mActions; for (int i = 0, count = mCount; i final HandlerAction handlerAction = actions[i]; handler.postDelayed(handlerAction.action, handlerAction.delay); }
mActiOns= null; mCount = 0; } }
private static class HandlerAction { final Runnable action; final long delay;
public HandlerAction(Runnable action, long delay) { this.action = action; this.delay = delay; }
This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ...
[详细]