android - 在 robospice 中暂停后台进程

标签 android asynchronous retrofit robospice

是否可以暂停当前正在运行的后台服务并从其执行停止点开始再次运行它?

如果不是,是否至少可以在 SpiceService 完成执行之前发送一个信号来停止其执行?

最佳答案

我不是 Robospice/Retrofit 专家。但是,这是关于 http 连接的一般问题。

要实现这一点,您需要编写低级代码来连接到服务器。打开服务流。这样你就可以检查流是否仍然打开。如果是,则将新数据添加到您的流已经从中获取数据以发送到服务的数组。

因为你正在使用这个库。这是不适用的。您唯一的解决方案是取消/停止连接并建立新连接。

这应该很简单:

if( spiceManager.isStarted() )
    spiceManager.cancel(String.class, MY_REQUEST_CACHE_KEY);

然后开始新的。

Note: There is a possibility that on checking if the spiceManager started to get a true. and before the cancelation the spiceManager connection finishes. In this case you should take in consideration to not submit the already submitted infos again. that would be a waste. It depend on your implementation. you may don't have to do extra work for this.

关于android - 在 robospice 中暂停后台进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31871644/

相关文章:

android - 当应用程序处于前台时检测 Android 7.0 Nougat 上的连接变化

android - 如何在 Tabbed Activity Android 的操作栏中为每个选项卡添加图标

具有可变参数模板的 C++ 异步无法找到正确的函数模板特化

c++ - boost asio 什么时候调用 async_read_some 回调?

java - 如何通过省略中介类来简化Retrofit

android - 在 Android Activity 之间运行自定义动画

android - 从系统服务到其他应用程序的异步通信

java - Retrofit 中未调用 onResponse 方法?

php - Retrofit-Callback.onFailure 被称为

java - 在 DDMS View 中找不到 CSV 文件?