@Retention(value=CLASS)
@Target(value=TYPE)
public @interface EBean
Should be used on custom classes to enable usage of AndroidAnnotations.
This class MUST have either a default constructor (ie without parameters) or
a constructor with only a parameter of type Context.
Your code related to injected beans should go in an AfterInject
annotated method.
If the class is abstract, the enhanced bean will not be generated. Otherwise, it will be generated as a final class. You can use AndroidAnnotations to create Abstract classes that handle common code.
Most annotations are supported in EBean classes, except the ones
related to extras. Views related annotations will only work if the bean was
injected in an activity with a layout containing the views you're dealing
with. If your bean needs a Context you can inject on by
using an RootContext annotated field.
Beans have two possible scopes : default or singleton. Default scope should be preferred but in some case it may be useful to use a singleton scope (mainly if you want to keep some runtime state in your bean).
The enhanced bean can also be injected in any enhanced class by using
Bean annotation.
Example :
@EBean
public class MyBean {
@RootContext
Context context;
@Bean
MySingletonBean mySingletonBean;
@AfterInject
void init() {
mySingletonBean.doSomeStuff(context);
}
}
@EBean(scope = Scope.Singleton)
public class MySingletonBean {
public void doSomeStuff(Context context) {
// ...
}
}
AfterInject,
RootContext,
Bean| Modifier and Type | Optional Element and Description |
|---|---|
EBean.Scope |
scope |
public abstract EBean.Scope scope
Copyright © 2010-2014. All Rights Reserved.