Search code examples
javaandroidannotationsinterception

Java - Use annotations and intercept methods?


Is there a simple way to intercept methods in java. I need to add an annotation to required methods so that a piece of logic gets called before going 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 guice library for android apps does not contain AOP. Is it possible to achieve this using reflection without adding any libraries?


Solution

  • Guice provides easy way of implementing annotations. Check this out.

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

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