0

I am performing an activity that takes long time(offline). I am sending and receiving(reading) sms in my app for this i am using a count down timer class which has a listener onTick() and onFinish(). in the onTick() listener i am checking if there is any new message and if there is any new message from the expected message it will stop the timer and display it on my screen. Everything seems to be okay. the problem arises when i leave and re-enter the app or change the orientation.

While working with network calls robospice takes care of all these activity transition problems. So I want to solve the above issue using robospice. I have seen the robospice offline example in the github. But there LoadDataFromNetwork() doesn't handle any listeners. It just performs a prolonged task.

If I had correlated the offline example with my problem then what I have to do is just call the spiceManager.execute() method inside my onTick() listener and the loadDataFromNetwork() will just read the message from my inbox and check if there is any message of desired kind and return that to the requestListeners. But that's not what I want. I want robospice to moderate the complete timer class.

I couldn't get how to fire robospice requestlisteners only when I read the specific required message as the reading activity is performed in timer ontick() Listener.

Is it actually possible with robospice to do like this ?? If not please give me a solution to deal with the actual problem mentioned in the first paragraph.

Systematix Infotech
  • 2,345
  • 1
  • 14
  • 31
Revanth Gopi
  • 350
  • 4
  • 14

1 Answers1

0

If you're switching to using RoboSpice then there doesn't seem to be any need for a CountDownTimer, you could implement your own polling in loadDataFromNetwork. This will be executed in a worker thread in a Service so blocking this thread will not affect your UI.

So a simple for loop with sleeps should get the same result.

One thing to be wary of is the number of threads your SpiceService is configured to work with. If this is a very long running task and you're using the default single worker thread then I believe you'll block subsequent SpiceRequests. If you haven't already subclassed the SpiceService class you can do so and override the getThreadCount method to return an int greater than 1.

darnmason
  • 2,672
  • 1
  • 17
  • 23