标签:
通过Choreographer的回调次数检测当前时刻运行的流畅度,原理参看:http://bugly.qq.com/blog/?p=166
正常一秒会有60次的回调
import android.app.Activity;
import android.util.Log;
import android.view.Choreographer;
public class CheckActivity extends Activity implements Choreographer.FrameCallback {
private long mTime = 0;
private long mNumber = 0;
@Override
public void doFrame(long frameTimeNanos) {
if (System.currentTimeMillis() - mTime >= 1000) {
Log.d("CheckActivity", "doFrame " + mNumber);
mNumber = 0;
mTime = System.currentTimeMillis();
} else {
mNumber++;
}
Choreographer.getInstance().postFrameCallback(this);
}
@Override
protected void onStart() {
super.onStart();
Choreographer.getInstance().postFrameCallback(this);
}
@Override
protected void onStop() {
super.onStop();
Choreographer.getInstance().removeFrameCallback(this);
}
}
标签:
原文地址:http://blog.csdn.net/wang_shaner/article/details/45690519