XTrace is a simple implementation of AOP on Android, treading through a series of pits. I hope to help you apply AOP to Android. Welcome to Star, Fork, and look forward to your valuable comments.

Here are my notes on trampling

AOP overview

Those of you who have done J2EE development must be very familiar with AOP. In J2EE, the implementation of section-oriented programming generally includes AspectJ, Spring AOP, etc. Sorry, I have only used these two. The main terms of AOP are: Aspect, Pointcut, Advise, etc. Here, I have chosen AspectJ as AOP for the Android platform.

The -xtrace instructions

XTrace targets methods with @Trace annotation. The main function of XTrace is to Log the execution method identifier, execution method name, execution parameter transmission value, execution time, and return value.

Run a screenshot

Usage:

@Trace("chat")
public void onChat(View view) {
    try {
        Thread.sleep(20);
    } catch (InterruptedException e) {
           e.printStackTrace(); }}@Trace("sum")
private int sum(int a, int b) {
    return a + b;
}Copy the code

You can use this to extend, for example, statistics on user behavior.