在Android设备上构建的CodeNameOne中的SocketTimeoutException [英] SocketTimeoutException in CodeNameOne build on Android device

查看:60
本文介绍了在Android设备上构建的CodeNameOne中的SocketTimeoutException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个CodeNameOne应用程序,该应用程序在仿真器的所有外观中均能正常工作.它在iPad上也可以正常工作.但不能在其他Android设备上使用.我已经尝试过三星平板电脑,华为MadiaPad(Android 4.1.2)和三星S4 mini(Android 4.2.2).

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).

应用程序建立连接以获取一些配置选项,此方法运行良好,并返回结果.接下来,它进行连接以获取大量数据.这将导致SocketTimeoutException.

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.

这是基本代码:

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);

如果我将该网址粘贴到浏览器中,则加载大约需要10秒钟.这很长,但是我不明白为什么会是问题所在.NetworkManager.getTimeout()给出300000.request.getTimeout()给出-1.我尝试将两个超时都设置为不同的值,但是现在我只是尝试随机操作,希望它可能有所帮助.

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.

令我特别惊讶的是,iPad和仿真器可以很好地处理这一问题.在某种程度上,Android设备中的某些内容用于处理更长的连接.有人可以帮我照一下吗?谢谢!

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!

推荐答案

Android的超时设置有所不同,因为某些设备/操作员在各种情况下都不稳定,导致无法连接的情况持续存在.

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.

仅供参考,您无需调用 NetworkManager.start().

FYI you don't need to call NetworkManager.start().

这篇关于在Android设备上构建的CodeNameOne中的SocketTimeoutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆