말랑말랑한 이야기2010. 9. 9. 20:28

Sunday, May 30, 2010

The limitations of AsyncTask

AsyncTask is a fine API, it's been said that it "holds your hand", and makes performing background operations painless. It pulls this off so well in fact, that I see people overusing it in situations where it's not really appropriate.

It's particularly unsuited for situations when you have a multiple tasks to perform concurrently. Imagine an Activity that needs to download about 30 small images from a remote server, and update the UI as these become available. AsyncTask uses a static internal work queue with a hard-coded limit of 10 elements. That means if you were to create an AsyncTask instance for each image, the work queue would quickly overflow and many of your tasks would get rejected. The best solution in this case is to create your own ThreadPoolExecutor instance that uses a queue that's large enough to hold all your tasks, if you need an unbounded queue, a LinkedBlockingQueue will work just fine.

Another severe limitation is that an AsyncTask can't survive your Activity being torn down and recreated on the other side.  Even if you pass it to the new instance via onRetainNonConfigurationState, the internal Handler inside the AsyncTask is still going to be stale and it's not going to behave correctly.  This is important to consider, and the Android documentation makes no mention of it all.  I've already blogged this scenario in detail, so I won't flog a dead horse here.

There are a few other minor issues, such as the fact that you can't change the background threads execution priority. It's hard-coded to a low priority, which granted, is the sensible default.  Also, exception handling is not very well supported.

So just to reiterate, AsyncTask is a nice API, but you should understand it's limitations and apply it appropriately.  If you're serious about writing mobile apps, then you're going to need a few more tools in the toolbox to get the job done.

Source: http://foo.jasonhudgins.com/2010/05/limitations-of-asynctask.html

Posted by Ditongs Ditongs

댓글을 달아 주세요

  1. It can accommodate 13 passengers and fly for 3, http://www.moncleroutletespain.com/ moncler españa,250 nautical miles without refueling. Passengers can fly non-stop from New York to London. Cabin features include executive leather seats, http://www.moncleroutletespain.com/ moncler, a divan and credenza, tables for group meals or meetings, http://www.moncleroutletespain.com/ moncler outlet, individual tables, a galley, http://www.moncleroutletespain.com/ moncler online, an enclosed lavatory, a wardrobe/storage cabinet, http://www.moncleroutletespain.com/ moncler chaquetas, a DVD player with two different sized LCD monitors and a voice/data communication system. So the next time you're flying, http://www.moncleroutletespain.com/ http://www.moncleroutletespain.com/, request the Embraer Legacy and get a taste of flying in real luxury for less!Related articles:


    http://hiddenchampion.tistory.com/741 http://hiddenchampion.tistory.com/741

    http://mba7.tistory.com/59 http://mba7.tistory.com/59

    2013.01.05 16:56 [ ADDR : EDIT/ DEL : REPLY ]

딱딱한 이야기2010. 8. 24. 05:08

우연히 손에 잡혀 읽게 된 책입니다. "무소유"를 읽고 난 직후에 집어든 책인데요. 저랑 인연이 닿은 모양입니다. 아무튼 요즘 느끼는 이슈랑 딱 맞아 떨어졌습니다. 저는 마켓 3.0 시대를 응원하고 있습니다. 잘 만든 백편의 광고보다 영향력 있는 한명의 블로거 글이 더 효과가 있는 세상이 온거죠. 인터넷을 등에 업고요. 스마트폰의 보급과 함께 마켓 3.0은 더욱 가속화 될 것 입니다. 마켓 4.0은 과연 어떤 모습일까요?

'딱딱한 이야기' 카테고리의 다른 글

Market 3.0  (0) 2010.08.24
Matrix  (0) 2010.08.24
Posted by Ditongs Ditongs

댓글을 달아 주세요

딱딱한 이야기2010. 8. 24. 04:57
드디어 매트릭스 영화를 봤습니다. 터미네이터 시리즈를 보면서 느꼈던 재귀적인 느낌을 다시 한번 느낄 수 있었습니다.
현실을 인식하지 못하고 그냥 메트릭스 안에서 평생 사는게 더 행복한건지도 모르겠습니다. 지금 우리가 그러는것 처럼요...

'딱딱한 이야기' 카테고리의 다른 글

Market 3.0  (0) 2010.08.24
Matrix  (0) 2010.08.24
Posted by Ditongs Ditongs

댓글을 달아 주세요