Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 465
qwerty Avatar asked Aug 07 '15 07:08

qwerty


2 Answers

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.

like image 62
hasan Avatar answered Oct 17 '22 08:10

hasan


You can try use 'wait()' which is a Object's method .It can pause current thread until you used 'notify()' or 'notifyAll()' with the same Object in other thread .

like image 32
wzg Avatar answered Oct 17 '22 07:10

wzg