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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:34:35+00:00 2026-06-04T02:34:35+00:00

I want to know how to use the CursorLoader to populate the widgets on

  • 0

I want to know how to use the CursorLoader to populate the widgets on a screen. All the examples online are only for using an adapter and this works great. What I need is a reliable way to update the views in my screen from a Cursor and on the UI thread and without sometimes crashing because of StaleDataException or the cursor being deactivated all of a sudden. Here is my current approach but I still receive some crash reports from users.

@Override
    public Loader<Cursor> onCreateLoader(int id, Bundle arg1) {
        CursorLoader loader = null;

        switch (id) {
            case LOADER_ID_DATA:
                loader = new CursorLoader(...);
                break;
        }

        return loader;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, final Cursor cursor) {
        handler.post(new Runnable() {

            @Override
            public void run() {
                if (getActivity() == null)
                    return;

                updateView(cursor);
            }
        });
    }

    @Override
    public void onLoaderReset(Loader<Cursor> arg0) {
    }

One solution would be to retrieve all the cursor fields directly inside onLoadFinished and pass them all to the handler to populate the widgets on the UI thread. But this is ugly because I may have a lot of values in the cursor. I would love to find a reliable crash-free way of dealing with all this.

  • 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-04T02:34:36+00:00Added an answer on June 4, 2026 at 2:34 am

    After asking on #android-dev SimonVT and readme helped me to get the bottom of this.

    There is nothing that states that onLoadFinished will be called on the UI thread so in theory you should use a Handler like advised in Reto’s book. However, when using a CursorLoader (which is by far the most common use case) you can pretty much guarantee that onLoadFinished will be called in the UI thread.

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

Sidebar

Related Questions

First i briefly want to know how you can use oauth works. What we
I want to know how to use this tal:repeat in my case. For example,
I'm using the Java Selenium RC and I want to know how to use
i just want to know the use of this script.. var gaJsHost = ((https:
This question may be subjective but i just want to know when to use
I want to know what is the use of .properties file and where it
i want to know that when we want to use push notification service.From where
I want to use push notification in my app.i want to know that do
I want to know how and when can I use the exit() function like
I Want to know which one is preferred while coding to use Static Methods

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.