Android中AsyncTask和Thread的使用場(chǎng)景

For long-running or CPU-intensive tasks, there are basically two ways to do this: Java threads, and Android's native AsyncTask.
Neither one is necessarily better than the other, but knowing when to use each call is essential to leveraging the system's performance to your benefit.
Use AsyncTask for:
<li>Simple network operations which do not require downloading a lot of data
<li>Disk-bound tasks that might take more than a few milliseconds

Use Java threads for:
<li>Network operations which involve moderate to large amounts of data (either uploading or downloading)
<li>High-CPU tasks which need to be run in the background
Any task where you want to control the CPU usage relative to the GUI thread

And there are lot of good resources over internet which may help you:
http://www.vogella.com/articles/AndroidBackgroundProcessing/article.htmlhttp://www.mergeconflict.net/2012/05/java-threads-vs-android-asynctask-which.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 所謂的獨(dú)立,不是針對(duì)在愛情里;在整個(gè)社會(huì)群體,都需要獨(dú)立,有一個(gè)可以自我獨(dú)立的能力很重要。 突然戀愛了,突然朋友來...
    孫大敏的癲狂閱讀 269評(píng)論 0 0
  • BottomNavigationView、下拉刷新、滑動(dòng)菜單一、BottomNavigationView在 bui...
    為夢(mèng)想戰(zhàn)斗閱讀 307評(píng)論 0 0
  • 冷得有點(diǎn)不知所措,于是加了件外套。還是行騎自行車上班。 來了位新同事,老大說,教下他。 嗯。怎么教?我最怕教人了,...
    流浪癡人閱讀 202評(píng)論 0 0
  • 還記得那一天 我輕輕地看了你一眼 還記得那一天 我愛上了你的笑臉 如果時(shí)間亙古不變 也許就不會(huì)忘了昨天 如果明天一...
    愛哭的流氓閱讀 275評(píng)論 0 0
  • 我的心底藏著一個(gè)秘密 尤其不能告訴的 是你 你說我們的友誼會(huì)天長(zhǎng)地久 我想我對(duì)你的愛將矢志不渝 你并不知道這個(gè)秘密...
    冰點(diǎn)晚安閱讀 304評(píng)論 4 6

友情鏈接更多精彩內(nèi)容