发射服务意向后阵列适配器和ListView问题 [英] Array adapter and listview issues after launching Intent Service

查看:154
本文介绍了发射服务意向后阵列适配器和ListView问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图被我的阵列适配器填充。现在一切,直到我在行上会启动一个异步任务,请单击工作正常。

I have a list view being populated by my array adapter. Now everything works fine until i click on a row which launches an async task.

我的异步任务应该下载一些图片的URL,并在它的onPostExecute下载图像,并将它们存储在SD卡的推出意图的服务。

My async task is supposed to download some image urls and launch an intent service in it's onPostExecute to download the images and store them on the SDcard.

这一切工作正常,但一旦我打回并重新启动片段中期网络运营,我的列表视图是空的,直到意图服务完成保持为空。可能是什么问题吗?我有一个的AsyncTask处理下载的目的服务,那么,为什么服务块的主线?

All this works fine but once i hit back and relaunch the fragment mid the network operations, my listview is empty and remains empty until the intent service is done. What could be the problem here? I have an AsyncTask handling the downloads in the intent service so why does the service "block" the main thread?

推荐答案

阅读围绕我终于找到了我在做什么错,主要是由于本的问题这里<一个href=\"http://stackoverflow.com/questions/23935531/problems-in-calling-asynctask-from-intentservice\">here. onHandleIntent 运行在辅助线程所以真的没有必要为我在意向服务,创建一个异步任务首位。所以我代替我的异步任务与方法的目的服务,并称为 onHandleIntent 的方法和解决了我的问题。

After reading around i finally found out what i was doing wrong, mainly due to this question here and here. onHandleIntent runs on a worker thread so there really was no need for me to create an Async task in the intent service in the first place. So i replaced my Async task in the intent service with a method and called that method in onHandleIntent and that solved my problem.

这篇关于发射服务意向后阵列适配器和ListView问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆