如何在android项目中使用bean? [英] how to use bean into android project?

查看:56
本文介绍了如何在android项目中使用bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用于 javaEE 项目 Spring,并且我使用带有 @Servive 注释的 bean 注入.现在我要制作 android 的项目,我想对我的服务 bean 使用类似的结构.有办法吗?

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?

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;

推荐答案

尝试使用 AndroidAnnotations.它不仅是 IoC,还是很棒的线程控制工具,还有许多其他特征.它有助于编写更少的代码并更友好地进行开发.

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.

这篇关于如何在android项目中使用bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆