本文介绍了安卓进程死亡 - 低资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与我写,而且还会请求URL每隔X分钟一个简单的HTTP GET请求有点问题。我每天有一次或两次,这一进程在GET请求中的中间停了下来。

I've a little problem with a simple HTTP GET request that I've written and which will request a URL every X minutes. I had it once or twice a day that the process stopped in the midst of the GET request.

下面是调试日志的例子:

Here's an example of the debug log:

12-07 16:29:22.650 V/TAG(11655): Executing HTTP Request
12-07 16:29:25.336 D/dalvikvm(11655): GC_CONCURRENT freed 366K, 50% free 2824K/5639K, external 0K/0K, paused 3ms+3ms
12-07 16:29:25.526 D/dalvikvm(11655): GC_CONCURRENT freed 450K, 52% free 2825K/5767K, external 0K/0K, paused 2ms+2ms
12-07 16:29:29.990 I/ActivityManager( 1339): Process PackageName:remote (pid 11655) has died.
12-07 16:29:29.990 I/ActivityManager( 1339): Low Memory: No more background processes.

现在这只是吐了两个问题对我来说:

Now this just threw up two problems for me:


  • 首先,我指定不工作超时:

  • First, the timeout that I've specified does not work:

    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 10000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    int timeoutSocket = 10000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    HttpClient client=new DefaultHttpClient(httpParameters);
    HttpGet request=new HttpGet(url);
    Log.v(TAG,"Executing HTTP Request");
    HttpResponse response=client.execute(request);


  • 第二个问题是,我不能看到一个原因的过程中已经死亡 - 这是'死'的消息相同的,如果它被杀死,由于低内存吗?由于超时还未到达这里(client.execute是在try / catch块)

  • The second problem is that I cannot see a reason why the process has died - is this the 'died' message the same if it is getting killed due to low memory? Because the timeout has not been reached here (client.execute is in a try / catch block)

    感谢您的答复!

    推荐答案

    如果我理解正确你问两件事情:

    If I understood you correctly you are asking two things:


    • Q1:为什么没有在指定的超时工作

    • Q2。没有这个过程,为什么死?

    与第二季度开始,我的猜测是,你的进程被杀死,因为超时没有工作,你的code花太长时间运行。因此Android的把它打死了。

    Starting with Q2, my guess is that your process is killed because the timeout didn't work and your code took too long to run. As a result Android killed it.

    至于Q1:我做了一些试验,发现在模拟器超时没有在我的应用程序正常工作。与模拟器API7和API8测试中,我总是得到一个的UnknownHostException 约20秒后,无论任何设置超时。这正好为 DefaultHttpClient 以及 HttpURLConnection类 AndroidHttpClient

    As for Q1: I did some experimenting and noticed that in the emulator the timeouts didn't work in my app as well. Testing with the emulator API7 and API8 I always get an UnknownHostException after about 20 seconds, regardless of any set timeout. This goes for the DefaultHttpClient as well as the HttpUrlConnection and AndroidHttpClient.

    谷歌搜索发现,其他人也纷纷报道了超时问题:

    Googling revealed that other people have also reported problems with timeout:





    • 超时使得当HTTPGET请求
    • http://code.google.com/p/android/issues/detail?id=2409
    • Http connection timeout on Android not working
    • http connection timeout issues
    • Socket timeout when making HTTPGet requests using DefaultHTTPClient

    提出的解决方案没有为我工作,所以我想的唯一可靠的解决办法是自己管理超时。

    None of the proposed solutions worked for me, so I guess the only reliable solution is to manage timeouts yourself.

    这篇关于安卓进程死亡 - 低资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 07-20 20:01