October 18, 2012 | 1min read
Android lacks method intercepting?!
How many of you wish to add some actions before/after invoking a method. Guice users will say “no problem, let’s use MethodInterceptor“.
It’s certainly possible via the standard Guice framework but what about Android’s lighter version: RoboGuice? Sadly Android’s VM doesn’t support bytecode generation on the fly - see the ‘Limitations’ section from link above. Originally my idea was to intercept methods annotated by @Background and run them in separate thread. But after some initial investigations, the results weren’t very promising.
However, it’s not all bad news! I’ve created my own implementation providing similar functionality. You can find the open source library android-method-interceptor on Google code. The project is based on Java’s Proxy objects and with help of RoboGuice solves the problem. Currently in Polidea we’re using @Transactional annotation for wrapping methods in database transactions.
Have fun! Please contact me if you have more ideas connected with this project.
You might also like
December 17, 2018
Polimag—How to Enhance Creativity through Digital Detox and Print
We have just published Polimag—a printed magazine, dedicated to our Clients! Dive in!
January 28, 2020
Accessibility—Mistakes to Avoid When Implementing it in an Android App
Not only UX designers but also developers should have accessibility in mind. Learn how to use TalkBack and make using your Android app easier for those visually impaired.