"Back" functionality and NetworkManager

34 views
Skip to first unread message

State Thirteen

unread,
Oct 25, 2013, 1:42:20 AM10/25/13
to codenameone...@googlegroups.com
Hi,

I am trying to keep "back" functionality available to the user. I have two forms. One with multibuttons and the other with a container. When user clicks on multibutton the second form showed and some network activity runs in "before" event. Container on the second form populated with data in postResponse() of the ConnectionRequest.
Now when I click Back the first form appears. Then I click another multibutton and the second form showed and another ConnectionRequest runs. When I do this several times I have bunch of network requests which are pollute my container with wrong data in the end. I have tried this workaround 

private void runSingleRequest(ConnectionRequest request){
Enumeration<ConnectionRequest> en = NetworkManager.getInstance().enumurateQueue();
while(en.hasMoreElements())
NetworkManager.getInstance().killAndWait(en.nextElement());
NetworkManager.getInstance().addToQueue(request);
}

but this doesn't kill any request at all. All requests were running till the end and update my data.
The question is How can I stop all network activity when leaving the form?

Shai Almog

unread,
Oct 25, 2013, 2:03:51 AM10/25/13
to codenameone...@googlegroups.com
Hi,
I suggest using kill not kill and wait.
The queue shows the future tasks not the one currently running, to kill the currently running task you will need to actually have a reference to it.
Generally its a bad idea to randomly kill networking requests, this can break your analytics code and various other features.

State Thirteen

unread,
Oct 25, 2013, 2:09:35 AM10/25/13
to codenameone...@googlegroups.com
> to kill the currently running task you will need to actually have a reference to it.

So I need to have one ConnectionRequest variable at the global scope and before creating new request I have to check it vs null and kill it first, right?

State Thirteen

unread,
Oct 25, 2013, 2:10:43 AM10/25/13
to codenameone...@googlegroups.com
Or how can I check that the request is running?

Shai Almog

unread,
Oct 25, 2013, 12:23:03 PM10/25/13
to codenameone...@googlegroups.com
We hide that sort of functionality. Since you send the request yourself so on back you should be able to know what you sent.
The idea is to hide the underlying behavior when possible.

If you just have one request going this should be trivial.

State Thirteen

unread,
Oct 25, 2013, 12:28:20 PM10/25/13
to codenameone...@googlegroups.com
I understood that killing is not the best way ) And it is very hard to kill ConnectionRequest. At least for me )
So I am not killing the requests now but synchronize data they provide.
Thanks for the clue)
Reply all
Reply to author
Forward
0 new messages