我写了一个简单的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