File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes Why handlers/AsyncTask are used? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Why handlers/AsyncTask are used?" Watch "Why handlers/AsyncTask are used?" New topic

Why handlers/AsyncTask are used?

gauravkv gupta

Joined: Feb 18, 2012
Posts: 21
I am new to Android technology, and after going through various post and blogs i understand the "What is handler/AsyncTask and how it is used" but i could not understand the fact that what we lose if we omit the Handlers and AsyncTasks from Android. So, i want to know "Why handlers are used and what problem handlers solve".

Please spare your valueable time and help me out in this.

Thanks in appreciation.
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

You cannot perform long running tasks on the UI thread on Android. Doing so will make the OS want to kill your app quickly. The OS usually waits for ~X seconds before waiting for your UI thread to return. To avoid being zapped by android, you can use a AsyncTask / Service to perform long running operations.

Here is a great video that explains async operations

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
I agree. Here's the link:
subject: Why handlers/AsyncTask are used?
It's not a secret anymore!