how to use bean into android project?

别等时光非礼了梦想. 提交于 2020-01-05 07:47:40

问题


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.



来源:https://stackoverflow.com/questions/15426486/how-to-use-bean-into-android-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!