Android: process dead - low resources?

I have a little problem with a simple HTTP GET request that I wrote and which will request a URL every X minutes. I had this once or twice a day when the process stopped in the middle of a GET request.

Here is an example 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 it just threw two problems for me:

  • At first, the timeout that I 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 don’t see the reason why the process died - is the message "dead" the same way if it is killed due to low memory? Since the timeout has not been reached here (client.execute is in the try / catch block)

Thank you for your responses!

+4
source share
1 answer

If I understand you correctly, you ask two things:

  • Q1: Why is the specified timeout not specified?
  • Q2. Why is the process dying?

Starting with Q2, I assume that your process has been killed because the timeout does not work and your code has worked too long. As a result, Android killed him.

As for Q1: I experimented a bit and noticed that timeouts in the emulator also do not work in my application. Testing with the API7 and API8 emulator, I always get an UnknownHostException after about 20 seconds, regardless of any timeout set. This applies to DefaultHttpClient , as well as to HttpUrlConnection and AndroidHttpClient .

Googling revealed that other people also reported timeout problems:

None of the proposed solutions worked for me, so I think that the only reliable solution is to manage timeouts on your own.

+2
source

Source: https://habr.com/ru/post/1385248/


All Articles