要须心地收汗马,孔孟行世目杲杲。这篇文章主要讲述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();
推荐阅读
- H5 打开App
- Android为TV端助力 使用shared注意事项
- 最近接触的几种APP支付方式——支付宝支付
- ABP框架用Dapper实现通过SQL访问数据库
- Android 解决ScrollView嵌套RecyclerView导致滑动不流畅的问题
- 利用create-react-app结合react-reduxreact-router4构建单页应用
- Android将Activity打成jar包供第三方调用(解决资源文件不能打包的问题)
- android studio生成aar包并在其他工程引用aar包
- Android四大组件之BroadcastReceiver