Use annotations and interception methods?

Is there an easy way to intercept methods in java. I need to add an annotation to the required methods so that a piece of logic is called before passing through the method.

public void verifyActivity() {
   // Asset if you are on a wrong page
}

@VerifyActivity
public void testLogin() {
   // Login for my automate test
}

@VerifyActivity
public void testSomethingElse() {
   // Test some other UI Automation stuff
}

EDIT:

The recommended library for Android apps does not contain AOP. Is it possible to achieve this with reflection without adding any libraries?

+5
source share
4 answers

Guice provides an easy way to implement annotations. Check this.

http://code.google.com/p/google-guice/wiki/AOP

http://code.google.com/p/google-guice/

+2
source
+1

, .

0

, - .

cglib, .

. "" , InvocationHandler, - .

0

All Articles