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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:30:59+00:00 2026-05-26T21:30:59+00:00

I have a class which will store a list of objects and will also

  • 0

I have a class which will store a list of objects and will also populate this list from a database (via a cursor) This will happen when I instantiate the object. I want to populate the list on a separate thread and then set a flag in the class when the list is populated. Do I need to use a handler or is that only for the UI thread?

Thanks,
m

This seems to work for me:

public void pop(){
    mReadyToSearch = false;
    new Thread() {
        public void run() { final Long startTime = System.currentTimeMillis();
                            Log.i(TAG, "Start Pop");

                            populateAnimalListFromCursor();
                            mReadyToSearch = true; 

                            final Long endTime = System.currentTimeMillis() - startTime; 
                            Log.i(TAG, "End Pop : "+ Long.valueOf(endTime)  +"ms");

                            }
        }.start();
}

Seems a bit simple but it loads the list and sets the state of the class which is all I need at the minute. Can anyone see a problem with this?

Thanks, m

  • 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-26T21:30:59+00:00Added an answer on May 26, 2026 at 9:30 pm

    If you instantiate the object from somewhere on the UI-thread, the instantation will also be run on the UI-thread.

    I suggest you add an AsyncTask (or a Runnable could do it, if you don’t need to update UI-components) as an inner class of your object to do the loading – this way it will be done from a non-UI-thread.

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

Sidebar

Related Questions

I have a class Cache which picks up List<SomeObject> someObjectList from DB and stores
I have made a LinkedList to store State objects which is a class I
I'm currently working on an oophp application. I have a site class which will
I have a static timer class which will be called by ANY webpage to
I have created a class for a dashboard item which will hold information such
I have a class which is marked with a custom attribute, like this: public
I have a class which looks something like this: public class Test { private
I have a class which inherits from QTreeWidgetItem and I intercept the click event.
In C++, I have an Object class, from which a number of other classes
I have written a class that will be used to store parameters in 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.