I/Choreographer: Skipped 85 frames! The application may be doing too much work on its main thread. I/Choreographer: Skipped 56 frames! The application may be doing too much work on its main thread.
这个日志,我想我们已经很熟悉了。我们如果应用比较卡顿掉帧的时候,控制台就会有这样的日志打印。
1 2 3
private static final int SKIPPED_FRAME_WARNING_LIMIT = SystemProperties.getInt( "debug.choreographer.skipwarning", 30);
@TestApi publicvoidpostCallbackDelayed(int callbackType, Runnable action, Object token, long delayMillis) { if (action == null) { thrownewIllegalArgumentException("action must not be null"); } if (callbackType < 0 || callbackType > CALLBACK_LAST) { thrownewIllegalArgumentException("callbackType is invalid"); }
privatevoidscheduleFrameLocked(long now) { //标志位,避免不必要的多次调用 if (!mFrameScheduled) { mFrameScheduled = true; if (USE_VSYNC) { if (DEBUG_FRAMES) { Log.d(TAG, "Scheduling next frame on vsync."); }
// If running on the Looper thread, then schedule the vsync immediately, // otherwise post a message to schedule the vsync from the UI thread // as soon as possible. //1 如果当前线程是UI线程,直接执行scheduleFrameLocked,否则通过Handler处理 if (isRunningOnLooperThreadLocked()) { scheduleVsyncLocked(); } else { Messagemsg= mHandler.obtainMessage(MSG_DO_SCHEDULE_VSYNC); msg.setAsynchronous(true); mHandler.sendMessageAtFrontOfQueue(msg); } } else { // mLastFrameTimeNanos 主要作用于当 USE_VSYNC = false 的时候,设置 doFrame 的时间 finallongnextFrameTime= Math.max( mLastFrameTimeNanos / TimeUtils.NANOS_PER_MS + sFrameDelay, now); if (DEBUG_FRAMES) { Log.d(TAG, "Scheduling next frame in " + (nextFrameTime - now) + " ms."); } Messagemsg= mHandler.obtainMessage(MSG_DO_FRAME); msg.setAsynchronous(true); mHandler.sendMessageAtTime(msg, nextFrameTime); } } }