我寫了一個簡單的HTTP GET請求,並且每隔X分鐘會請求一個URL,這有點問題。這個過程在GET請求中停止,我每天有一兩次。Android:進程已經死亡 - 資源不足?
這裏的調試日誌的例子:
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.
現在,這只是把兩個問題對我來說:
首先,我指定的超時不起作用:
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塊中)
感謝您的回覆!
看起來像Android殺死了你的進程,因爲它在後臺運行,它需要內存。 – THelper
可以防止這種情況嗎? –
是(通過使用服務)和否(服務仍然可以在低內存中被Android殺死,但不太可能)。閱讀[本博客](http://android-developers.blogspot.com/2010/04/multitasking-android-way.html),特別是關於「在後臺顯式運行」的部分。 – THelper