标签: robospice

在运行时更改改造OkHttpClient的ConnectionTimeout

我正在使用Dagger注入RestAdapter.Builder,我正在该函数中创建一个OkHttpClient.功能如下:

@Provides
@Singleton
@Named("JSON")
public RestAdapter.Builder provideJsonRestAdapterBuilder(final ChangeableEndpoint changeableEndpoint,
                                                         final Set<RequestInterceptor> requestInterceptors) {
    final OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setConnectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS);
    okHttpClient.setWriteTimeout(Constants.WRITE_TIMEOUT, TimeUnit.SECONDS);
    okHttpClient.setReadTimeout(Constants.READ_TIMEOUT, TimeUnit.SECONDS);

    try {
        okHttpClient.setCache(new Cache(mApplication.getCacheDir(), Constants.CACHE_SIZE));
    } catch (final IOException e) {
        LOG.warn(e.getMessage(), e);
    }

    final Gson gson = new GsonBuilder()
        .registerTypeAdapter(Date.class, new DateDeserializer())
        .registerTypeAdapter(AbstractAction.class, new AbstractActionDeserializer())
        .create();

    return new RestAdapter.Builder()
        .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : retrofit.RestAdapter.LogLevel.NONE)
        .setConverter(new GsonConverter(gson))
        .setEndpoint(changeableEndpoint)
        .setClient(new OkClient(okHttpClient))
        .setRequestInterceptor(new RequestInterceptor() {

            @Override
            public void intercept(final RequestFacade request) {
                for (final RequestInterceptor requestInterceptor : …
Run Code Online (Sandbox Code Playgroud)

android robospice dagger retrofit

6
推荐指数
0
解决办法
1959
查看次数

android.os.Service上下文中的Robospice

根据RoboSpice文档https://github.com/octo-online/robospice/wiki/Design-of-RoboSpice,我可以在任何上下文中使用它.

无法在服务上下文中找到使用Robospice的示例.我做了一些尝试,但没有发生任何事情,请求只是没有执行,没有例外(也许一些日志泄漏,我需要做什么来启用robospice登录设备?)

  1. 在哪里开始/停止它?(spiceManager.start(this)/ spiceManager.shouldStop())
  2. 在哪里创建SpiceManager实例?(我的服务在application.onCreate()方法中启动,也许我必须等待一些SpiceService初始化?)

一些代码

public abstract class SpicyService extends Service {

    private SpiceManager spiceManager = new SpiceManager(SpiceService.class);

    @Override
    public void onCreate() {
        super.onCreate();
        spiceManager.start(this);
    }

    @Override
    public void onDestroy() {
        spiceManager.shouldStop();
        super.onDestroy();
    }
}
Run Code Online (Sandbox Code Playgroud)

service android robospice

5
推荐指数
1
解决办法
2063
查看次数

RoboSpice使用OrmLite保留JSON数组

我正在使用RoboSpice和Spring for Android,并希望使用OrmLite持久保存JSON对象数组.GSON用于JSON编组.使用默认缓存,一切都按预期工作.但OrmLite似乎不喜欢对象数组.

这是JSON的简化版本:

[{"id": 1, "title": "Test 1"},{"id": 2, "title": "Test 3"},{"id": 3, "title": "Test 3"}]
Run Code Online (Sandbox Code Playgroud)

我想在以下对象中坚持这一点:

@DatabaseTable
public class Foo {
    @DatabaseField(id = true)
    private int id;
    @DatabaseField
    private String title;

    // getters and setters
    ...
}
Run Code Online (Sandbox Code Playgroud)

基于RoboSpice OrmLite示例,我创建了以下GsonSpringAndroidSpiceService类来添加OrmLite CacheManager.这是问题开始的地方.

public class CustomGsonSpringAndroidSpiceService extends GsonSpringAndroidSpiceService
{
    @Override
    public CacheManager createCacheManager(Application application)
    {
        // add persisted classes to class collection
        List<Class<?>> classCollection = new ArrayList<Class<?>>();
        classCollection.add(Foo.class);

        // init
        CacheManager cacheManager = new CacheManager();
        cacheManager.addPersister(new InDatabaseObjectPersisterFactory(
            application, new RoboSpiceDatabaseHelper(
                application, …
Run Code Online (Sandbox Code Playgroud)

java spring json ormlite robospice

5
推荐指数
1
解决办法
4316
查看次数

在RoboSpice请求Android中设置连接超时

我在Android中使用RoboSpice for Rest Api通话,我想在通话中添加30秒钟的连接超时,我该怎么办?

这是我的代码

 public class AddBrandsService extends
        SpringAndroidSpiceRequest<AddBrands.Response> {

     public final AddBrands.Response loadDataFromNetwork(){

     return getRestTemplate().postForObject(url,
            request, AddBrands.Response.class);
    }

    }


    this service is called here 

    private SpiceManager contentManager = new SpiceManager(
        JacksonSpringAndroidSpiceService.class);

    contentManager.execute(service, lastRequestCacheKey,
                DurationInMillis.ONE_SECOND, new AddBrandsListner());
Run Code Online (Sandbox Code Playgroud)

提前致谢...

android robospice

5
推荐指数
1
解决办法
2181
查看次数

使用robospice ormlite清除旧缓存数据

我使用ormlite来缓存sqlite数据库Robospice.缓存后的数据如下所示:

table cacheentry(由robospice生成)

rowid  cachekey      resultclass            resultIntegerId      timestamp
-------------------------------------------------------------------------------
  1      113     com.sq.src.EventResult            3             1381938044268
Run Code Online (Sandbox Code Playgroud)

EventResult

id     data     timestamp
-------------------------
1       121    1381938211268
2       122    1381938444278
3       123    1481938785422 
Run Code Online (Sandbox Code Playgroud)

当时间到期时,robospice将请求并添加新的行数据EventResult.
问题是我想只清除以下旧数据(清除行ID 1,2和保持行ID 3)EventResult:

getSpiceManager().removeDataFromCache(EventResult.class,113);
Run Code Online (Sandbox Code Playgroud)

但它只清除了cacheentry表中的缓存键行.
这一个清除了所有表格中的所有数据.

 getSpiceManager().removeAllDataFromCache();
Run Code Online (Sandbox Code Playgroud)

你能否告诉我如何控制清除旧数据并将最新的数据与robospice保持在一起?提前致谢.

更新:EventResult已被许多其他表引用,我必须清除它们中的所有引用行.

sqlite android ormlite robospice

5
推荐指数
0
解决办法
977
查看次数

如果应用程序进入后台然后来到Foreground,Robospice请求永远不会结束?

我正在开发一个使用RoboSpice库来调用REST API的应用程序.除了一件事,图书馆的一切都很好.我不使用RoboSpice中提供的缓存,因此所有请求都是在没有缓存的情况下完成的.现在,当任何请求正在进行并且用户按下home按钮时,调用onStop(),其中调用spice manager的shouldStop(),取消注册所有请求监听器以进行通知.当应用程序再次出现在前台时,由于未通知侦听器,因此不会发生UI更新.

我不想使用Robospice提供的Cache.有没有其他方法可以在不使用缓存的情况下获取UI更新通知?

android robospice

5
推荐指数
1
解决办法
945
查看次数

如何使用RoboSpice连接待处理的请求(启动>主要活动)?

我对RoboSpice(高级用法)的问题很少.

注意:我使用RoboSpice OrmLite.

我的Android应用程序由两个主要活动组成:第一个是SplashActivity(启动时开始),第二个是MainActivity(在启动屏幕后推出5秒).我在启动时执行了2个请求:

SplashActivity

public class SplashActivity extends BaseActivity {

    private fooRequest fooRequest;
    private barRequest barRequest;
    private exampleRequest exampleRequest;
    private NewsRequest newsRequest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        fooRequest = new fooRequest();
        barRequest = new barRequest();
        ...
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // Launch MainActivity...
            }
        }, 5000);
    }

    @Override
    protected void onStart() {
        super.onStart();

        getSpiceManager().execute(fooRequest, new Integer(0), DurationInMillis.ONE_DAY, new fooRequestListener());
        getSpiceManager().execute(barRequest, new Integer(1), DurationInMillis.ONE_DAY, new barRequestListener());
    } …
Run Code Online (Sandbox Code Playgroud)

android ormlite robospice

5
推荐指数
1
解决办法
2143
查看次数

使用 RoboSpice 和 RxJava

我想知道将 RoboSpice 和 RxJava 一起使用时的最佳实践是什么。到目前为止,我唯一发现的是RoboSpice Google Group 中“RoboSpice 和 RxJava”线程。我想知道在集成这两个库时是否有推荐的方法

android robospice rx-java

5
推荐指数
0
解决办法
774
查看次数

如何使用 T 和 List&lt;T&gt; 生成类

我正在尝试泛化我的班级结构。
我将更具体地展示我的真实结构。

我正在编写支持离线模式的应用程序,因此我决定使用RobospiceGreenDao ORM来实现我的 ETag 缓存机制。

我只需要缓存GET请求。

首先,我的请求应该扩展基本请求(不是我的),就我而言 RetrofitSpiceRequest<T, V>

T is type of return data   
V is service type, in my case I am  using Retrofit.
Run Code Online (Sandbox Code Playgroud)

问题是List of T默认情况下返回类型不是类型,我需要创建扩展 T 对象数组并将其用作返回类型的子类。

像这样的东西

public class City {
....
....
....
    public static class List extends ArrayList<City> {
    .....
    .....
    }

}
Run Code Online (Sandbox Code Playgroud)

并使用 City.List 作为返回类型。

但是我的 DAO 声明如下

public class CityDao extends AbstractDao<City, Long> {

}
Run Code Online (Sandbox Code Playgroud)

在每个请求 (GET) 中,我需要将特定的 DAO 作为成员,以便缓存与服务器数据不同的数据。或者在没有连接的情况下从本地数据库加载数据。

这里的问题是请求由 T …

java generics android caching robospice

5
推荐指数
1
解决办法
4979
查看次数

使用RoboSpice与Jackson2和Spring

我想用Jackson2 SpringRoboSpice.我的libs文件夹包含以下jar.

  • 公地IO-1.3.2.jar
  • 公地lang3-3.2.1.jar
  • 杰克逊的注解 - 2.2.3.jar
  • 杰克逊核心2.2.3.jar
  • 杰克逊 - 数据绑定 - 2.2.3.jar
  • robospice-1.4.11.jar
  • robospice缓存,1.4.11.jar
  • robospice-弹簧Android的1.4.11.jar
  • 弹簧Android的核心1.0.1.RELEASE.jar
  • 弹簧Android的休息模板,1.0.1.RELEASE.jar

如果写的jackson2罐子,这里 写的SpringAndroidSpiceService将切换到jackson2.

应用程序因此异常而崩溃:

java.lang.NoClassDefFoundError: org.codehaus.jackson.map.ObjectMapper
            at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.<init>(MappingJacksonHttpMessageConverter.java:54)
            at com.octo.android.robospice.JacksonSpringAndroidSpiceService.createRestTemplate(JacksonSpringAndroidSpiceService.java:33)
            at com.octo.android.robospice.SpringAndroidSpiceService.onCreate(SpringAndroidSpiceService.java:26)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2572)
            at android.app.ActivityThread.access$1800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

android jackson robospice

4
推荐指数
1
解决办法
1299
查看次数

标签 统计

robospice ×10

android ×9

ormlite ×3

java ×2

caching ×1

dagger ×1

generics ×1

jackson ×1

json ×1

retrofit ×1

rx-java ×1

service ×1

spring ×1

sqlite ×1