Nice to see other people adventuring into aspectJ and Android :-)
When using aspectJ with android you are limited to compile-time weaving, which basically means that you can only intercept code you own.
The first example works because when using the execution() pointcut the code gets weaved "inside" your Activitiy.onCreate().
The second example does not work, because the advice would have to get weaved into the methods that call your activity's onCreate. That's probably something like the ActivityManager that you cannot modify.
As a reference, here's what I use in development:
public aspect LogAspect {
public String ATAG = "LogAspect";
pointcut tolog1() : execution(* Activity+.*(..)) ;
before() : tolog1() {
String method = thisJoinPoint.getSignature().toShortString();
Log.d(ATAG, "=========== entering " + method+", parms="+Arrays.toString(thisJoinPoint.getArgs()));
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…