接上篇Android.animation cts fail
1.针对第二项testCurrentPlayTime:耗时是在sendMessage和handleMessage之间,
我在sendMessage后面加了如下的log,打印出当前的消息队列中有哪些消息:
Log.d(TAG, "animationHandler.sendEmptyMessage(ANIMATION_START),currenttime is"+AnimationUtils.currentAnimationTimeMillis());
animationHandler.sendEmptyMessage(ANIMATION_START);
animationHandler.dump(newPrinter() {
@Override
publicvoid println(String x) {
Log.d("sendmessage",x);
}
},"");
}
发现有别的消息阻塞在那里,导致我们的超时,log如下:
D/ValueAnimator( 2353): animationHandler.sendEmptyMessage(ANIMATION_START),currenttimeis 441442
D/sendmessage( 2353): Handler(android.animation.ValueAnimator$AnimationHandler) {41470bf0} @ 441444
D/sendmessage( 2353): Looper{41436d40}
D/sendmessage( 2353): mRun=true
D/sendmessage( 2353): mThread=Thread[main,5,main]
D/sendmessage( 2353): mQueue=android.os.MessageQueue@41436d60
D/sendmessage( 2353): Message 0:{ what=1000 when=-19ms }
D/sendmessage( 2353): Message 1:{ what=0 when=-19ms }
D/sendmessage( 2353): Message 2:{ what=0 when=-5ms }
D/sendmessage( 2353): (Total messages: 3)
I/ActivityManager( 1327): Displayedcom.android.cts.animation/android.animation.cts.AnimationActivity: +311ms
D/OpenGLRenderer( 1827): Flushing caches (mode 0)
D/ValueAnimator( 2353): handleMessage:ANIMATION_START 441510
从log中可以看出发送消息到Handler处理中间只有2ms,但是到处理handleMessage:ANIMATION_START却是441510-441444=66ms。
问题是:怎么能够不让消息队列里的别的消息阻塞我们的时间呢??
2. 针对第三项testSetCurrentPlayTime:
是setCurrentPlayTime()函数中的animationFrame()消耗了时间,调用这个函数用了超过1ms,所以导致fail。
D/ValueAnimator( 2356): setCurrentPlayTime!!!currentTime is460959
D/ValueAnimator( 2356): beforeanimationFrame-----------mStartTime is 450959currentTime is 460959
D/ValueAnimator( 2356): animationFrame come in come in----------- 460959
D/ValueAnimator( 2356): fraction is is is 33.333332mStartTime=450959 currentTime=460959
D/ValueAnimator( 2356): start call animateValue
D/ValueAnimator( 2356): animateValue come in come in come in
D/ValueAnimator( 2356): afteranimationFrame-----------currentTime is 460960