How do i check for request failure after resuming activity?

195 views
Skip to first unread message

Maxim Komarovsky

unread,
Apr 14, 2013, 2:35:33 AM4/14/13
to robo...@googlegroups.com
Hi!

First, thanks a lot for your lib, it does make life much easier :)
Second, here is the question: 

1. Somewhere in my Activity i start a (potentially long-running) SpiceRequest by calling
SpiceManager.execute(...);

2. The activity gets stopped and/or destroyed

3. On resume i call
SpiceManager.getFromCache(...);
SpiceManager.addListenerIfPending(...);

Everything works as expected except the case when the request fails before the activity gets resumed or re-created. The only callback I get is OnRequestSuccess(...) with null result after calling getFromCache().
That seems correct as there has been no result to cache and return, but how do I find out that the request has failed?

I could do something like this:

class MyRequest implements SpiceRequest<X extends RequestResultWithError> {
@Override
public X loadDataFromNetwork() throws Exception {
X result;

try{
result = loadData();
} catch(Exception e) {
result.setError(e);
}

return result;
}
}

the request would ALWAYS return a cacheable result, but is there any "built-in" functionality for that case?

Thanks you!
max77

Adam Mackler

unread,
Apr 20, 2013, 1:00:05 PM4/20/13
to robo...@googlegroups.com
Dobjanschi instructs adding two columns to your database tables, one for status, one for result.  If you insert data into the database before making the network call and set the status to "creating", and your activity checks the database for incomplete requests everytime it starts, then it will see the "creating" status of a failed request and can reinvoke the request.  Obviously the request listener methods need to update these two columns as necessary.


On Sunday, April 14, 2013 2:35:33 AM UTC-4, Maxim Komarovsky wrote:
how do I find out that the request has failed?
...
max77

Stéphane Nicolas

unread,
May 1, 2013, 2:22:08 AM5/1/13
to robo...@googlegroups.com
Hi Maxi and Adam,

no such facility is provided in RS. Requests and their status are not persisted, only their results are. I believe that the solutions you propose are valid : creating a custom request that will persist the status of the request separatly.

I wish I also had some time to investigate combining RS and Tape from Square, it could also offer request status persistence.

S.


2013/4/20 Adam Mackler <adamm...@gmail.com>

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes RoboSpice.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 



--
Stéphane NICOLAS,
OCTO Technology 
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - blog.octo.com
www.usievents.com
...........................................................

鄧風鈴

unread,
Jul 17, 2013, 1:55:31 PM7/17/13
to robo...@googlegroups.com
I have the same problem but I think that your solution is not always OK. 
The processor process request in processRequest will return when it see a NoNetworkException.

Vào 13:35:33 UTC+7 Chủ nhật, ngày 14 tháng tư năm 2013, Maxim Komarovsky đã viết:

Stéphane Nicolas

unread,
Jul 17, 2013, 1:57:50 PM7/17/13
to robo...@googlegroups.com
The hook method `requestFailure` will be invoked in your listener. You could save that information.


2013/7/17 鄧風鈴 <langx...@gmail.com>

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes RoboSpice.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 
Reply all
Reply to author
Forward
0 new messages