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

  • Home
  • SEARCH
  • 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 6813737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:36:18+00:00 2026-05-26T20:36:18+00:00

I have an AsyncTask that queries a content provider and does some additional processing

  • 0

I have an AsyncTask that queries a content provider and does some additional processing in the onPostExecute() of that task. I have a stack trace for an exception that is very hard to reproduce, but I would like to guard against the condition or fix the code. The code is below:

int i = 0;
mIds = new long[cursor.getCount()];
while (cursor.moveToNext()) {
    mIds[i++] = cursor.getLong(COLUMN_ID);
}

The crash is happening on the line in the loop. The way I see it, the only way this could happen
is if:

  1. cursor.getCount() is returning an incorrect count.
  2. cursor is changed while this loop is executing, but I don’t think that’s possible
    because cursor is a local variable. Perhaps something underlying the cursor has changed that I’m not aware of.
  3. mIds has changed. This shouldn’t be possible because we are running
    on the UI thread and this is the only place in which that variable is assigned
    a new value. By the nature of onPostExecute running on the UI thread, it shouldn’t be possible for this code to be running somewhere else at the same time, right?

Am I missing something?

  • 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-26T20:36:19+00:00Added an answer on May 26, 2026 at 8:36 pm

    It’s difficult to see what is wrong with that loop without seeing the full code but I note from the docs:

    Cursor implementations are not required to be synchronized so code using a Cursor from multiple threads should perform its own synchronization when using the Cursor.

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

Sidebar

Related Questions

I have a AsyncTask that runs and does its job and completes. onPostExecute does
I have a network task defined inside of an AsyncTask that takes approximately 2-3
I have AsyncTask that processes some background HTTP stuff. AsyncTask runs on schedule (Alarms/service)
In my project I have a AsyncTask that fetches some JSON data from the
So I have this AsyncTask that loads a WebView in onPostExecute that otherwise works
In my app I have a background task (using AsyncTask) that downloads stuff from
I have an API in one jar that uses AsyncTask to carry out some
I have a content provider which is going out to some record sources in
I have some AsyncTask that loads a video stream into the player, so I
I have an AsyncTask that get info from the web. Sometimes the connection fails

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.