在 robospice 中暂停后台进程

Pause a background process in robospice

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

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

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

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

因为你正在使用这个库。这是不适用的。你唯一的解决办法是 cancel/stop 连接并建立一个新连接。

这应该很简单:

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.

您可以尝试使用 'wait()',这是一个对象的方法。它可以暂停当前线程,直到您在其他线程中对同一对象使用 'notify()' 或 'notifyAll()'。