stephanenicolas / robospice

Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules.
Apache License 2.0
2.95k stars 545 forks source link

Is there a way to re-attach listeners to a running SpiceRequest? #375

Closed jagg18 closed 10 years ago

jagg18 commented 10 years ago

I am executing a SpiceRequest from my activity. It uses publishProgress() to update a progress bar in my UI. However, when a user presses the Home button, or opens a new activity, onStop() is called and hence, spiceManager.shouldStop() is also called and listeners are detached. I do understand this is needed to prevent memory leaks.

Now when I go back to the app/activity, my progress bar does not get updated anymore even if my request is still running. Is there a way to re-attach a listener to this request? I cannot use addListenerIfPending() since the request is already running and re-executing the request is not an option. Can you point me to the right direction? TIA.

nkeskinov commented 10 years ago

Please check the following StackOverflow answer from the creator of RoboSpice: http://stackoverflow.com/a/24181943/754439:

addListenerIfPending will not trigger any request by itself, it only allows to plug a listener to an already pending request if such a request exists.

The addListenerIfPending() method is exactly what you need.

Also, please note that the preferred way of posting questions is https://groups.google.com/forum/#!forum/robospice.