loadDataFromNetwork() called twice on long-running request

174 views
Skip to first unread message

Maxim Komarovsky

unread,
Jan 25, 2014, 12:31:56 PM1/25/14
to robo...@googlegroups.com
Hi there! :)

The code below is taken from robospice-samples and slightly modified by me just for testing...

public class GitHubRequest extends SpringAndroidSpiceRequest<GitHubUser.List> {

...blabla

    @Override
    public GitHubUser.List loadDataFromNetwork() throws Exception {
   Log.d("XXX", "requesting...");
   
 
// The delay is inserted to simulate a "long-running" request
   Thread.sleep(10000);

   return getRestTemplate().getForObject(url, GitHubUser.List.class);
    }
}

The idea is to find out what will happen if a user rotates a device while request is in progress.

case 1:
        spiceManagerJson.execute(new GitHubRequest("android"), "github", DurationInMillis.ALWAYS_RETURNED, new GitHubUserListListener());

Everything is OK, the requests get aggregated and loadDataFromNetwork() is called once no matter how many times I rotate the device. Cached result is used in subsequent requests.

case 2:
        spiceManagerJson.execute(new GitHubRequest("android"), "github", DurationInMillis.ONE_SECOND * 10, new GitHubUserListListener());

Weird things start happening here. If rotate the phone right after the app is launched, everything is just the same as in case 1.
Then I wait for 10+ seconds to be sure the data in cache is obsolete and rotate the device. loadDataFromNetwork() gets called. That's OK.
Then I rotate again (the request is still running) and... loadDataFromNetwork() gets called one more time!
If I keep rotating nothing happens. Finally, the listener is called once as it should.

The logic seems really strange. Or this is a bug? :)

Regards,
Maxim Komarovsky




Maxim Komarovsky

unread,
Jan 25, 2014, 12:40:28 PM1/25/14
to robo...@googlegroups.com
JFYI: tested on RS 1.4.9 and 1.4.11

суббота, 25 января 2014 г., 23:31:56 UTC+6 пользователь Maxim Komarovsky написал:

Stéphane Nicolas

unread,
Jan 25, 2014, 1:45:59 PM1/25/14
to robo...@googlegroups.com
Are you sure it's not related to the retry policy ? Does any request fail ?

Stéphane


2014-01-25 Maxim Komarovsky <m.koma...@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 - mobilite.octo.com 
blog.octo.com - www.usievents.com
...........................................................

Максим Комаровский

unread,
Jan 25, 2014, 1:58:03 PM1/25/14
to robo...@googlegroups.com

Hi Stéphane!

No, the request has completed successfully. I tried to debug the app and found out that the 2nd request does not get aggregated while the 3rd and others do. In fact both requests are completed according to logs. I mean they go through all states (pending/loading from cache(fail)/loading from network/writing to cache).

26 янв. 2014 г. 0:45 пользователь "Stéphane Nicolas" <snic...@octo.com> написал:
--
Vous recevez ce message car vous êtes abonné à un sujet dans le groupe Google Groupes "RoboSpice".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/robospice/OoAJlpxRg04/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.

Максим Комаровский

unread,
Jan 25, 2014, 1:59:22 PM1/25/14
to robo...@googlegroups.com

Anyway I'll keep on debugging when I get back home...

26 янв. 2014 г. 0:58 пользователь "Максим Комаровский" <m.koma...@gmail.com> написал:

Stéphane Nicolas

unread,
Jan 25, 2014, 2:08:05 PM1/25/14
to robo...@googlegroups.com
Thx Maxim, let me know what you come up with. If you are sure, there is a bug, open an issue on GitHub.

S.


2014-01-25 Максим Комаровский <m.koma...@gmail.com>

nischitha S

unread,
Mar 16, 2015, 8:22:33 PM3/16/15
to robo...@googlegroups.com, snic...@octo.com
i am seeing the same problem. i using the latest build i see that loadDataFromNetwork is called twiced when the result set returned by the network call is null.
Reply all
Reply to author
Forward
0 new messages