How can I define a pointcut for a method injected with ApsectJ?
I have injected the method as follows and it works properly:
public void com.moeActivity.onBackPressed() {
super.onBackPressed();
Log.d("ATAG", "BACKK");
}
Now am trying to define a pointcut to detect the execution of the injected method but it is not successful, I tried the following:
pointcut eventActivity():
execution(* com.moeActivity.onBackPressed(..));
Any help would be appreciated
Thanks!
You need an advice body to run the enjected method (e.g.
Log.d("ATAG", "BACKK")
probably) inside of it like this:Doing this, the after advice connects with the named pointcut called eventActivity and runs the crosscutting action (i.e.
Log.d("ATAG", "BACKK")
) aftersuper.onBackPressed()
. As @kriegaex says, you need to read some AspectJ examples to comprehend it efficiently.