Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:45:02+00:00 2026-06-13T10:45:02+00:00

Quoting the documentation for AsyncTask found here , it says: AsyncTasks should ideally be

  • 0

Quoting the documentation for AsyncTask found here, it says:

AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent pacakge such as Executor, ThreadPoolExecutor and FutureTask.

Now my question arises: why? The doInBackground() function runs off the UI thread so what harm is there by having a long running operation here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:45:04+00:00Added an answer on June 13, 2026 at 10:45 am

    It is a very good question, it takes time as an Android Programmer to fully understand the issue. Indeed AsyncTask have two main issues that are related :

    • They are poorly tied to the activity life cycle
    • They create memory leaks very easily.

    Inside the RoboSpice Motivations app (available on Google Play) we answer that question in detail. It will give an in-depth view of AsyncTasks, Loaders, their features and drawbacks and also introduce you to an alternative solution for network requests : RoboSpice.
    Network requests are a common requirement in Android and are by nature long running operations
    .
    Here is an excerpt from the app :

    The AsyncTask and Activity life cycle

    AsyncTasks don’t follow Activity instances’ life cycle. If you start an AsyncTask inside an Activity and you rotate the device, the Activity will be destroyed and a new instance will be created. But the AsyncTask will not die. It will go on living until it completes.

    And when it completes, the AsyncTask won’t update the UI of the new Activity. Indeed it updates the former instance of the activity that
    is not displayed anymore. This can lead to an Exception of the type java.lang.IllegalArgumentException: View not attached to window manager if you
    use, for instance, findViewById to retrieve a view inside the Activity.

    Memory leak issue

    It is very convenient to create AsyncTasks as inner classes of your Activities. As the AsyncTask will need to manipulate the views
    of the Activity when the task is complete or in progress, using an inner class of the Activity seems convenient : inner classes can
    access directly any field of the outer class.

    Nevertheless, it means the inner class will hold an invisible reference on its outer class instance : the Activity.

    On the long run, this produces a memory leak : if the AsyncTask lasts for long, it keeps the activity “alive”
    whereas Android would like to get rid of it as it can no longer be displayed. The activity can’t be garbage collected and that’s a central
    mechanism for Android to preserve resources on the device.


    It is really a very very bad idea to use AsyncTasks for long running operations. Nevertheless, they are fine for short living ones such as updating a View after 1 or 2 seconds.

    I encourage you to download the RoboSpice Motivations app, it really explains this in-depth and provides samples and demonstrations of the different ways to do some background operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quoting the Android developer guide found here here its says Additionally, the Andoid UI
Today I saw a post on php.net, that I'm quoting here: $Bar = a;
I've been quoting this segment from Sun's document for the past few days, and
Quoting a comment from here : If you want to debug on a single
I've got few doubts regarding quoting mysql queries in Zend framework. Though this question
I am quoting a part of Python documentation: A program doesn’t run any faster
Quoting from the SQLite web page If the page_size pragma is used to specify
The C++ standard (quoting from draft n3242) says the following about subobjects [intro.object]: Unless
Quoting from this nice article , The new view scope should solve exactly those
Quoting from here , In C, there are two different namespaces of types: a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.