how to use bean into android project?

2019-08-09 10:52发布

问题:

I use for javaEE project Spring, and I use bean injection with @Servive annotation. Now I'm going to make android's projects and I'd like to use the similar structure for my service bean. Is it a way to do it?

i.e.

public interface GlobalService {
final static String PACKAGE_ACTIVITY = "net.....activity.";

    /**
    * start an activity only by the activity name
    * the intent is declared inside
    * @param activityName
    * @return True if the activity Start else False
    */
public boolean openActivity(String activityName);
 }

then I have a class that implements interface

 @Service("GlobalService")
 public class GlobalServiceImpl implements GlobalService{

 public boolean openActivity(String activityName) {
    //some code ....
 }
}

finally I declare into my class

@Autowired
private GlobalService globalService;

回答1:

Try to use AndroidAnnotations. It's not only IoC, but also great threading control tool and has many other features. It helps to write less code and does development more freindly.