使用RoboSpice与Roboguice

时间:2013-04-23 13:32:30

标签: android roboguice robospice

是否有任何示例显示我们如何将一类SpringAndroidSpiceRequest对象注入到我们的活动中。这是我的班级

public class GenericService<E> extends  SpringAndroidSpiceRequest<E> {

    public GenericService(Class<E> clazz) {
        super(clazz);

    }

    @Override
    public E loadDataFromNetwork() throws Exception {
        return null;
    }

}

现在我不能为这个类提供一个无参数构造函数,因为我不能简单地在构造函数中说E.class,因为设计的限制。我能做的就是说

class MyService extends GenericService<Login.Response>{

    public MyService() {
        super(Login.Response.class);

    }

}

然后将MyService的值注入我的活动中。但是这个approch意味着必须为我的每个请求对象创建一个专门的类[大概有32 :(]。任何人都可以告诉我如何实现我想要做的事情?

亲切的问候

1 个答案:

答案 0 :(得分:2)

在我们的真实应用中,我们为每个请求都有一个专门的请求类。这是robospice的模型。继承有时可以帮助概括请求,但通常最终会为每个休息服务创建一个请求。