Home » Android » java – Bean and EBean conception Android Annotations

java – Bean and EBean conception Android Annotations

Posted by: admin May 14, 2020 Leave a comment


sorry I am newbie in Android Annotations and Dependency Injection in general. I am trying to understand how things work and what benefits I get using Android Annotations.
I have studied sample examples, everything is clear about @EActivity, @ViewById, @App and other widely used annotations in Android development.
I have problems with understanding concep of Ebean. I have used spring for Java, it is quite clear that we are declaring beans in xml file and just using them inside code in the way that we can easily change inside xml file only providing concrete implementation and it will be changed everywhere where we have used bean by Id from AppContext.
But I don’t understand the purpose of using beans in case of Android Annotations, may be I don’t understand DI in general.

public class MyClass {
  // ...  

public class MyActivity extends Activity {

  MyClass myClass;


What benefit we have here ? Are we ommiting only line
myClass = new MyClass(); ?
And thats all ?
Another example is Singletone scope.

@EBean(scope = Scope.Singleton)
public class MyClass {
  // ...  

In this case we have some benefit, we don’t have to create manually instance, private constructor and check if it is null (lazy initialization) …..

For this case I understand that it can save time, but in first example it seems not to have any benefits for me, we have no xml file where we can build our bean dependencies between beans only annotations.
Please help me to understand this.
Thanks everyone in advance.

How to&Answers: