Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android and Dependency Injection [closed]

I've been looking around, in vain, for some information on using a dependency injection container in Android development. Specifically, how to override the creation of an Activity in a way that will also work when coming back from being killed (for whatever reason).

Has anyone got any experience in this area?

like image 432
Richard Szalay Avatar asked Jan 25 '10 20:01

Richard Szalay


People also ask

What is Android dependency injection?

Dependency injection (DI) is a technique widely used in programming and well suited to Android development. By following the principles of DI, you lay the groundwork for good app architecture. Implementing dependency injection provides you with the following advantages: Reusability of code. Ease of refactoring.

What is dependency injection for?

Dependency injection is a programming technique that makes a class independent of its dependencies. It achieves that by decoupling the usage of an object from its creation. This helps you to follow SOLID's dependency inversion and single responsibility principles.

What is use of dagger 2 in Android?

Dagger 2 is a compile-time android dependency injection framework that uses Java Specification Request 330 and Annotations. Some of the basic annotations that are used in dagger 2 are: @Module This annotation is used over the class which is used to construct objects and provide the dependencies.

Does Android Studio still support Java?

On May 7, 2019, Kotlin replaced Java as Google's preferred language for Android app development. Java is still supported, as is C++.


2 Answers

You might also want to consider Spring ME. Although originally intended for Java ME, I have seen reports from people using it for Android as well. The benefit would be that you have a familiar programming model (Spring) without the penalty: Spring ME has a 0k footprint.

like image 21
Wilfred Springer Avatar answered Oct 02 '22 16:10

Wilfred Springer


It appears you can use Google Guice 2.0 with Android. You might also look into roboguice.

Edit:

Spring is also now available for Android

Edit: Roboguice is now deprecated. You might try Toothpick as mentioned in the comments by the developer behind Toothpick.

like image 142
Jay Askren Avatar answered Oct 02 '22 16:10

Jay Askren