17

What would be the best way to implement Aspect-oriented programming (AOP) in an Android application?

Would it be efficient with the mobile battery?

3
  • 2
    How does AOP relate to the battery? While AOP may be technically implemented as injecting code in methods, surely the effect on the battery would be the same as if said code was run some other way? Commented Sep 21, 2010 at 10:11
  • I guess it's just down to efficiency. If AOP is a more efficient way of implementing your code it'll be easier on the battery. However this would be a very hard thing to measure, and the effect probably very slight. Commented Sep 21, 2010 at 10:14
  • Fernando Cejas has written a blog post about AOP in Android. Basically, you can use two approaches: 1. Using AspectJ 2. Using Dynamic Proxy. fernandocejas.com/2014/08/03/… Commented May 2, 2018 at 9:06

1 Answer 1

17

It depends in how it is implemented.

For instance, AspectJ's compile-time weaving would work on android but runtime weaving do not. Android does not support bytecode generation.

Check the Guice wiki:

Behind the scenes, method interception is implemented by generating bytecode at runtime. Guice dynamically creates a subclass that applies interceptors by overriding methods. If you are on a platform that doesn't support bytecode generation (such as Android), you should use Guice without AOP support.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.