优雅的测量启动时间方法:AOP

1、AOP介绍

  Aspect Oriented Programming,面向切面编程

  针对同一类问题的统一处理

  无侵入添加代码

1.1AspectJ使用(辅助AOP实现)

  classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.0'

  implementation 'org.aspect:aspectjrt:1.8.+'

  apply plugin:'android-aspectjx'

1.2 Join Points

  程序运行时的执行点,可以作为切面的地方

    函数调用、执行

    获取、设置变量

    类初始化

1.3 PoindCut

  带条件的JoinPoints

1.4 Advice

  一种Hook,要插入代码的位置

    Before:PointCut 之前执行

    After:PointCut 之后执行

    Around:PointCut之前,之后分别执行

 

posted @ 2021-01-16 20:18  白一粥  阅读(82)  评论(0)    收藏  举报