Tag Archives: guice

Improving RoboGuice Application Start Times

RoboGuice is a fantastic dependency injection framework for Android that wraps Google’s Guice DI library with a set of helper classes and default injections that can make an Android developer’s life much easier. Unfortunately, this comes at a cost. Guice was not designed with mobile devices in mind and instead targets servers where objects startup is long but once you’re up, responses need to be quick. Because of this, startup times for apps using RoboGuice can be noticably long in the best case and uncomfortably long if you’re not careful. Below are some tips and tricks I’ve used to help defer that startup cost and improve the experience for the user. Continue reading Improving RoboGuice Application Start Times

DI on Android Without the Startup Cost: dagger

Anyone who has used a dependency injection (DI) framework on a project can likely speak to its benefits when creating complex systems. Relying on it can help an engineer to design and implement clean, testable software.

Anyone who has tried to write Android applications using a DI framework has likely been disappointed in some degree with current offerings. DI frameworks in Java have largely been written with server architectures in mind and as such are either generally too resource heavy to work on a mobile device. There have been some success stories, but they come with issues of their own. RoboGuice, the Android DI go to, is built around Google’s Guice. Roboguice is easy to set up and very powerful, but it comes with a cost. Because it uses run-time validation of the dependency tree, any application that uses it incurs a startup cost the first time it requests injection. On simple projects with few injected dependencies, this may be less than half a second, but I have seen it go as high as 1.5 on the latest hardware with more complex apps. There are ways to delay this cost or minimize the impact it has on the user experience (another post for another time), but the cost won’t go away.

Enter dagger: Continue reading DI on Android Without the Startup Cost: dagger