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

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

问题描述

我用的JavaEE项目的春天,我用豆注射@Servive注释。
现在,我准备做Android的项目,我想使用类似的结构为我服务的bean。它是一个办法做到这一点?

 公共接口GlobalService {
最终静态字符串PACKAGE_ACTIVITY =净.....活动。    / **
    *只有活动名称开始活动
    *意图是内部声明
    * @参数activityName
    * @返回True如果活动开始还有假
    * /
公共布尔openActivity(字符串activityName);
 }

然后我有一个实现接口的类

  @Service(GlobalService)
 公共类GlobalServiceImpl实现GlobalService { 公共布尔openActivity(字符串activityName){
    //一些code ....
 }
}

最后,我宣布了我的班

  @Autowired
私人GlobalService globalService;


解决方案

尝试使用 AndroidAnnotations 。这不仅的IoC ,也是伟大的线程控制的工具,有许多其他特征。它有助于少写code和发展做更多的业间友好的。

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;

解决方案

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.

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

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