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 8777061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:12:13+00:00 2026-06-13T19:12:13+00:00

I have an AsyntTask which starts in onCreate and loops infinitely, updating an UI

  • 0

I have an AsyntTask which starts in onCreate and loops infinitely, updating an UI element.

The update is done in this manner (simplified representation of the Async extending class, let’s call it asyncExtender().execute()):

doInBackground(){
    while (!isCancelled()) {
        Thread.sleep(2000);
        publishProgress(someValue);
    }
}
protected void onProgressUpdate() {
    super.onProgressUpdate(values);
    // UI update here, e.g. TextView.setText
}

Another activity is started, let’s call it SecondActivity. SecondActivity takes advantage of the hierarchical back button in the action bar to return to the previous activity (NavUtils.navigateUpFromSameTask(this) in onOptionsItemSelected).

The issues is that when I tap on the back button in the action bar in SecondActivity, the AsyncTask seems to not run anymore in the first activity (the UI doesn’t get updated every 2 seconds). On the other hand, if I use the hardware “back” button it works fine – the AsyncTask keeps running.

Why the difference in behaviour and how to fix it?

  • 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-13T19:12:14+00:00Added an answer on June 13, 2026 at 7:12 pm

    AsyncTasks should not be started simultanously and they also are not designed to be run for too long, at most few seconds. Depending which API you target, AsyncTasks might be run synchronously, so your new AsyncTask will be run only when all previous ones finished, excerpt for docs:

    http://developer.android.com/reference/android/os/AsyncTask.html

    When first introduced, AsyncTasks were executed serially on a single
    background thread. Starting with DONUT, this was changed to a pool of
    threads allowing multiple tasks to operate in parallel. Starting with
    HONEYCOMB, tasks are executed on a single thread to avoid common
    application errors caused by parallel execution.

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

Sidebar

Related Questions

I have an Activity which starts an AsyncTask. This AsyncTask uses AutoCompleteTextView.showDropDown() in onPostExecute.
I have an update database operation, that has an activity, which keeps updating the
I have an Android app which uses a service to continuously update a textview
I have to download a file and I'm using this code , which is
I have a class which is used to get media file thumbs. This Loader
So, in my Dialog, I have a button which starts an Asynctask downloader to
I have a listview which is filled with data form sqlitedatabase. A list-view element
I have an AsyncTask which starts on boot (called by a service). In some
I've got an TabActivity implementing TabContentFactory, which starts an AsyncTask in onCreate() to fetch
I have this this code for Android which is stuck at the synchronized statement.

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.