Android: Process has died - low resources?

六月ゝ 毕业季﹏ 提交于 2019-12-23 13:57:10

问题


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

Thanks for your replies!


回答1:


If I understood you correctly you are asking two things:

  • Q1: Why doesn't the specified timeout work?
  • Q2. Why did the process die?

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.

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:

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



来源:https://stackoverflow.com/questions/8424425/android-process-has-died-low-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!