2

I have requirements where jobs are required to be done in background.I read about the best practices for background jobs at Android website.

Here its written

the Android framework offers several classes that help you off-load operations onto a separate thread running in the background. The most useful of these is IntentService.

I also came across something named as AsyncTask where they mentioned

This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

I was not able to decide which one should I use.Also I may have to consider the fact that android eventually kill apps when it wants to reclaim memory.

Now I am left with the questions :-

  1. What are the deciding factors for choosing between AsyncTask and IntentService ?
  2. Which one will be the best choice considering android's memory reclaim nature ,so that the app's background job should be done gracefully?

Please help me with it..

Abhinav
  • 1,720
  • 4
  • 21
  • 33
  • Check these earlier posts: http://stackoverflow.com/questions/15167152/should-i-use-asynctask-or-intentservice-for-my-application http://stackoverflow.com/questions/3817272/android-design-considerations-asynctask-vs-service-intentservice http://stackoverflow.com/questions/9037500/intentservice-service-or-asynctask – Nitin Sethi Nov 22 '13 at 08:52

1 Answers1

0

AsyncTask is best because it is run any task on background asynchronous and when task is running condition call defferent method which is doBackground when task is complete call onPostExicute so in case of memory Asynktask is better.

nilesh patel
  • 834
  • 1
  • 5
  • 10
  • Even IntentService handles asynchronous requests (expressed as Intents) on demand.Check its [doc](http://developer.android.com/reference/android/app/IntentService.html).Sorry I don't agree with your answer. – Abhinav Nov 22 '13 at 09:02