0

So I have gone through the developer site: https://developer.android.com/training/articles/perf-anr.html

So I came to a conclusion :avoid intensive tasks via worker thread. So should use Asyctask, Intent Service and Handlers.

Also these three tasks have some limitations:

Asynctask:

  1. It could not be used for long running operations
  2. Cannot be used when using multiple asynchronous operations and and the need for UI change, will become more complicated

IntentService

  1. Works requests run sequentially.
  2. Operation running cannot be interrupted

Now keeping this in mind, as Handler and IntentServices could be used for long running operation.

can anybody help me with the difference between Handler and IntentService ? Like when should I use Handler and when IntentService and which is better to use?

Also what is the best approach to run request asynchronously?

prat
  • 597
  • 8
  • 17
  • From your link, **The most effecive way to create a worker thread for longer operations is with the AsyncTask class.** so why "It could not be used for long running operations"? (hey...I found a typo :) ) – petey Oct 22 '15 at 18:17
  • I have gone through the link . So if you are using Asynctask for long running operations, it will prevent other Asynctask from ever running. – prat Oct 22 '15 at 18:31
  • you are severely mistaken, handler and intent service are totally different, please read about them properly via authentic links. – Sarthak Mittal Oct 22 '15 at 18:38
  • Please correct me..it will help me – prat Oct 22 '15 at 18:39
  • Regarding the poolsize of AsyncTask, if you create more tasks the than the pool size all tasks created after the pool size is reach will wait for started tasks to complete (or be canceled) before allowing the next one to start. This is expected. Now, if YOU have to create more AsyncTasks that you WANT to run at the same time and that is more than is allowed...you will prolly want to change that pool size (by looking at the code for asynctask, copying it, and making relevant changes). – petey Oct 22 '15 at 18:59

0 Answers0