Pause a background process in robospice
Asked Answered
N

2

9

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?

Nu answered 7/8, 2015 at 7:9 Comment(6)
I think you need to update your question with RoboSpice in title. What you just described has nothing to do with Retrofit - it does not run it's own services.Phylogeny
Are you saying that you want to pause a connection on server? and stop streaming data? then continue the streaming?Nuts
@hasan83 If it is possible to do so, yes. If not, at least to stop the execution of the bg process before it ends (in my case, it is a heavy process that if the user modifies a set of parameters in an activity, this bg process also needs to be modified and this process is too heavy to wait for its completion and running it again with the new parameters).Nu
Does the response expected from the service changes when the parameters values passed to the service "changes"?Nuts
@hasan83 Yes, the response should also change.Nu
I believe that my answer is an appropriate one since you don't have the option of having a stream using Robospice. other option would be to wait until the current request finishes before starting a new one. but it's harder to be implemented and produces many situation to test against. which will increase the chance of bugs occurrences.Nuts
N
4

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.

Nuts answered 10/8, 2015 at 9:32 Comment(0)
T
1

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 .

Thalassa answered 17/8, 2015 at 8:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.