是否可以暂停当前正在运行的后台服务并从其执行停止点开始再次运行它?
如果不是,是否至少可以在 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/