Android性能优化知识点梳理 -- StrictMode
2025-02-19 本文已影响0人
捉影T_T900
本文针对Android应用开发过程中,会用到的性能优化工具及使用、注意事项进行介绍说明
StrictMode
严酷模式,主要检测两大问题,一种是线程策略(TreadPolicy),一种是VM策略(VmPolicy)
线程策略包括
detectAll() 表示全部异常都监控
- 线程执行缓慢,detectCustomSlowCalls()
执行缓慢需要代码透出缓慢信息,StrictMode.noteSlowCall - 主线程磁盘读操作,detectDiskReads()
- 主线程磁盘写操作,detectDiskWrites()
- 主线程网络操作,detectNetwork()
- 资源不匹配,detectResourceMismatches()
- 未缓冲的输入/输出操作,detectUnbufferedIo()
VM策略包括:
detectAll() 表示全部异常都监控
- Activity泄漏,detectActivityLeaks()
- 权限检查,detectContentUriWithoutPermission()
- 未关闭Closable对象泄漏,detectLeakedClosableObjects()
- Sqlite对象泄漏,如游标未关闭,detectLeakedSqlLiteObjects()
- 实例数检测,setClassInstanceLimit()
开启检测后,logcat会打印 StrictMode 相关提示
截屏2025-02-17 15.41.42.png