Search code examples
androidasynchronousretrofitrobospice

Pause a background process in robospice


Is it possible to pause a background service currently running and running it again starting from the point its execution was stopped?

If not, is it at least possible to send a signal to stop the execution of SpiceService before it finishes its execution?


Solution

  • I am not a Robospice/Retrofit expert. But, this is a general question about http connection.

    To achieve that you need to write a low level code to connect to the server. to open a stream to the service. this way you can check if the stream is still open. if yes add the new data to an array that your stream already takes data from to send to service.

    Since you are using this library. This is not applicable. your only solution is to cancel/stop the connection and establish a new one.

    This supposed to be easy:

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

    And, then start a new one.

    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.