How can the event sequence of a call to the specified application classes be deployed in time? By the example of Activity lifecycle, in onCreate, onResume, onPause, etc. - You can manually insert a call to Log.d in each method. In LogCat, the sequence of calls becomes clear. It would be desirable to carry out the similar in other classes of initial examples in which there can be much more methods. Is there a Log.d automation or similar tool? The trace method produces a lot of unnecessary information over which additional manipulations are required when studying. Or is the trace the only suitable way ?!

    1 answer 1

    You can use Aspect-Oriented Programming.

    Add dependencies:

    build.gradle

    dependencies { ... classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.14' } 

    app / build.gradle

     apply plugin: "android-aspectj" ... dependencies { ... compile 'org.aspectj:aspectjrt:1.8.9' } 

    Write aspect:

    LogAspect.java

     @Aspect public class LogAspect { private static final String TAG = "aspect"; @Before("execution(* *(..)) ") public void doBeforeAyMethod(JoinPoint joinPoint) { if(joinPoint.getTarget() != null) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Log.i(TAG, joinPoint.getTarget().getClass().getSimpleName() + " : " + method.getName()); } } } 

    Now all methods of classes of your application will be written to the log. It is worth remembering that this will work with the methods directly in the class, the methods of the superclass will not fall into the log only if they are overridden.

    And if you write your annotation, for example:

    MethodLog.java

     @Target(ElementType.TYPE) public @interface MethodLog { } 

    To annotate it with the necessary classes, and add to the aspect:

     @Before("execution(* *(..)) && @within(MethodLog)") 

    The methods of only selected classes will fall into the log.

    • 2
      Thanks katso! This is what is needed! - BuzZer
    • In one of the projects, I used the solution from: classpath 'me.leolin:android-aspectj-plugin:1.0.7' , and apply plugin: 'me.leolin.gradle-android-aspectj' , because when used (classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.14') gradle gave build errors. - BuzZer