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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:24:05+00:00 2026-05-20T12:24:05+00:00

I have a very strange problem. I have an AsyncTask which appears to block

  • 0

I have a very strange problem. I have an AsyncTask which appears to block the UI thread when I rotate the phone.

First, let me state that I’m comfortable with my Activity being destroyed and recreated on rotation. I save the AsyncTask in onRetainNonConfigurationInstance(), detach the Activity from it in onDestroy(), and reattach to it in onCreate() using getLastNonConfigurationInstance().

This is all fine, as long as the AsyncTask is doing no heavy work. For example, to debug my problem, I have this, and it works exactly as expected with no UI blocking:

@Override
protected Boolean doInBackground(Void... params) {
    boolean success = false;
    final DbAdapter dbAdapter = dbService.getAdapter();

    try {
        // pretend to do some complicated work
        Thread.sleep(20000);
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return success;
}

However, if I change it to do some actual work in the background, then I get a very long delay between onPause() being called to start the rotation, and onResume() being called later in the new orientation. This delay is in the tens of seconds, during which time the UI is in an inconsistent state (old layout cropped in the new orientation) and it seems as if the rotation is blocking on the AsyncTask. The only change is the two lines inside the try block:

@Override
protected Boolean doInBackground(Void... params) {
    boolean success = false;
    final DbAdapter dbAdapter = dbService.getAdapter();

    try {
        // actually do some complicated work
        XmlParser parser = new XmlParser(context, dbAdapter);
        success = parser.parse(source);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return success;
}

The context is a global application context passed in to the AsyncTask‘s constructor, so I don’t think I’m accidentally retaining a reference to the outgoing Activity.

What else could be going wrong?

  • 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-05-20T12:24:06+00:00Added an answer on May 20, 2026 at 12:24 pm

    Possibly your activity is also trying to use dbAdapter, and you have proper synchronization going on to prevent two threads from using dbAdapter at the same time.

    Possibly your activity is trying to load stuff off of the file system on the main application thread, and your database operations are causing too much contention. On hardware, YAFFS2 is effectively single-threaded for I/O operations.

    You can use Traceview to attempt to get more information about what is taking up your time, and you can use StrictMode on Android 2.2 and higher to see where your activity might be trying to do file I/O on the main application thread.

    Also, if your AsyncTask is converting XML into database entries, perhaps this is a better use of an IntentService rather than an AsyncTask.

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

Sidebar

Related Questions

I have a very strange problem in which identical pieces of Javascript are behaving
Im having a very strange problem, i have a complicated view that returns incorrect
I have a very strange memory leak problem, it seems that sqlite3_step is doing
We have a very strange problem which we have yet to be able to
I have a very strange problem, which took already several hours of my attention:
I have what appears to be a very strange problem. I have a HashMap
I have a very strange problem with #any? printing true for an array that
I have a very strange problem, i have an iframe that is able to
i have a very strange problem which i cannot solve at the moment. i
I have a very strange problem: The instance of my DTO that is non-null

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.