Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

android - Array adapter and listview issues after launching Intent Service

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.

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...