Reputation: 13
I've build a CodeNameOne application that works fine in all skins in the emulater. It also works fine on an iPad. But not on different Android devices. I've tried a Samsung tablet, Huawei MadiaPad (Android 4.1.2), and a Samsung S4 mini (Android 4.2.2).
The app makes a connection to get some configuration options, this works well, it returns the result. Next it makes a connection to get a larger amount of data. This results in a SocketTimeoutException.
This is the basic code:
NetworkManager networkManager = NetworkManager.getInstance();
networkManager.start();
ConnectionRequest request = new ConnectionRequest()
{
@Override
protected void readResponse(InputStream input) throws IOException
{
// some response handling
}
@Override
protected void handleException(Exception err)
{
//some error handling
}
};
request.setUrl(url);
request.setPost(false);
networkManager.addToQueue(request);
If I paste the url into a browser, it takes about 10 seconds to load. Which is pretty long, but I don't see why that would be the problem. NetworkManager.getTimeout() gives 300000. request.getTimeout() gives -1. I've tried setting both timeouts to different values, but now I'm just trying random things, hoping it might help.
What surprises me especially is that iPads and emulators handle this just fine. Somehow there is something different in Android devices for handling a longer connection. Can someone please shine some light on this for me? Thank you!
Upvotes: 0
Views: 160
Reputation: 52760
Android has a different timeout setting since some devices/operators are flaky in various cases and cause a dead connection to linger.
I'm guessing your timeout value is set after the submission of the connection request, to make sure just add something like:
request.setTimeout(120000);
Before invoking the add to queue method.
FYI you don't need to call NetworkManager.start()
.
Upvotes: 0