Should I use AsyncTask or IntentService for my application?

前端 未结 8 641
陌清茗
陌清茗 2020-12-12 21:48

I have been reading around on internet connectivity with Android and noticed there are different ways to handle this i.e. AsyncTask and IntentService. However, I\'m still no

相关标签:
8条回答
  • 2020-12-12 22:38

    You should use an AsyncTask for short repetitive tasks that are tightly bound to an activity, like what you're currently trying to do. IntentService are more geared towards scheduled tasks (repetitive or not) that should run on the background, independent of your activity.

    0 讨论(0)
  • 2020-12-12 22:42

    As mentioned above AsyncTask will solve your problem.

    But Keep in mind that AsyncTask has an important weakness: it doesn't handle well Activity "refresh" (eg during rotation). It may be a problem if, e.g., user rotate the phone while your AsyncTask is still loading stuff. If this is indeed a problem for you I recommend AsyncTaskLoader:

    http://developer.android.com/reference/android/content/AsyncTaskLoader.html

    0 讨论(0)
提交回复
热议问题