1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| public class SuperHandler extends Handler {
private long mStartTime = System.currentTimeMillis();
public SuperHandler() { super(Looper.myLooper(), null); }
public SuperHandler(Callback callback) { super(Looper.myLooper(), callback); }
public SuperHandler(Looper looper, Callback callback) { super(looper, callback); }
public SuperHandler(Looper looper) { super(looper); }
@Override public boolean sendMessageAtTime(Message msg, long uptimeMillis) { boolean send = super.sendMessageAtTime(msg, uptimeMillis); if (send) { GetDetailHandlerHelper.getMsgDetail().put(msg, Log.getStackTraceString(new Throwable()).replace("java.lang.Throwable", "")); } return send; }
@Override public void dispatchMessage(Message msg) { mStartTime = System.currentTimeMillis(); super.dispatchMessage(msg);
if (GetDetailHandlerHelper.getMsgDetail().containsKey(msg) && Looper.myLooper() == Looper.getMainLooper()) { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("Msg_Cost", System.currentTimeMillis() - mStartTime); jsonObject.put("MsgTrace", msg.getTarget() + " " + GetDetailHandlerHelper.getMsgDetail().get(msg));
Log.i("MsgDetail " , jsonObject.toString()); GetDetailHandlerHelper.getMsgDetail().remove(msg); } catch (Exception e) { } } } }
|