Android 最简单的测试UI卡顿

要须心地收汗马,孔孟行世目杲杲。这篇文章主要讲述Android 最简单的测试UI卡顿相关的知识,希望能为你提供帮助。
【Android 最简单的测试UI卡顿】就两个类:

public class BlockDetectByPrinter {
private static final String START = "> > > > > Dispatching";
private static final String END = "< < < < < Finished";
public static void start(){
Looper.getMainLooper().setMessageLogging(new Printer() {
@Override
public void println(String x) {
if(x.startsWith(START)){
LogMonitor.getsInstance().startMonitor();
}
if(x.startsWith(END)){
LogMonitor.getsInstance().startMonitor();
}
}
});
}
}



public class LogMonitor {
private static LogMonitor sInstance = new LogMonitor();
private HandlerThread mLogThread = new HandlerThread("log");
private Handler mIoHandler;
private staticfinal long TIME_BLOCK = 2000L;

private LogMonitor(){
mLogThread.start();
mIoHandler = new Handler(mLogThread.getLooper());
}
private static Runnable mLogRunnable = new Runnable() {
@Override
public void run() {
StringBuilder sb = new StringBuilder();
StackTraceElement[] stackTrace = Looper.getMainLooper().getThread().getStackTrace();
for(StackTraceElement s:stackTrace){
sb.append(s.toString()+"\n");
}
LogUtil.e("LogMonitor",sb.toString());
}
};
public static LogMonitor getsInstance(){
return sInstance;
}
//public boolean isMonitor(){
//return mIoHandler.hasCallbacks(mLogRunnable);
//}
public void startMonitor(){
mIoHandler.postDelayed(mLogRunnable,TIME_BLOCK);
}
public void removeMonitor(){
mIoHandler.removeCallbacks(mLogRunnable);
}

}
然后在application的onCreate方法使用
BlockDetectByPrinter.start();
































































    推荐阅读