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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:35:45+00:00 2026-05-30T02:35:45+00:00

I’ve got a CursorLoader in a ListFragment (that is inside a ViewPager ) that

  • 0

I’ve got a CursorLoader in a ListFragment (that is inside a ViewPager) that queries a database. I have a content provider for that database, which I’ve verified works.

The issue is this: when the app runs for the very first time a separate service calls a bulk insert in a ContentProvider:

public int bulkInsert(Uri uri, ContentValues[] values) {
    if(LOGV) Log.v(TAG, "insert(uri=" + uri + ", values" + values.toString() + ")");

    final SQLiteDatabase db = openHelper.getWritableDatabase();
    final int match = uriMatcher.match(uri);

    switch(match) {
        case SNAP: {
            db.beginTransaction();
            for(ContentValues cv : values) {
                db.insertOrThrow(Tables.SNAP, null, cv);                        
            }
            db.setTransactionSuccessful();
            db.endTransaction();

            getContext().getApplicationContext().getContentResolver().notifyChange(uri, null);
            return values.length;
        }

The CursorLoader in the list fragment returns 0 rows though on the very first run (when the database gets created). If I close and restart the app then the CursorLoader works great and returns exactly what I need. I’ve tried to implement waiting via a handler, but it doesn’t seem to help. Here is the ListFragment that utilizes the CursorLoader:

public class DataBySnapFragment extends ListFragment implements LoaderCallbacks<Cursor> {   
    public static final String TAG = "DataBySnapFragment";

    protected Cursor cursor = null;
    private DataBySnapAdapter adapter;

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Log.d(TAG, "RELOADING!!!!!");
            onLoadDelay();
        }
    };  

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d(TAG, "onActivityCreated");

        adapter = new DataBySnapAdapter(getActivity(), 
                                        R.layout.list_item_databysnap, 
                                        null, 
                                        new String[]{}, 
                                        new int[]{}, 
                                        0);
        setListAdapter(adapter);        
        getLoaderManager().initLoader(0, null, this);       
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_databysnap, null);
        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("error_workaround_1",
                           "workaroundforerror:Issue 19917,
                           http://code.google.com/p/android/issues/detail?id=19917");
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        CursorLoader cursorLoader = new CursorLoader(getActivity(),
                                                     Snap.CONTENT_URI,
                                                     null,
                                                     null,
                                                     null,
                                                     Snap.DATA_MONTH_TO_DATE + " DESC LIMIT 6");

        return cursorLoader;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        Log.d(TAG, "data rows: " + data.getCount());
        if(data.getCount() <= 0) {
            delayThread();
        } else {
            adapter.swapCursor(data);           
        }
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        adapter.swapCursor(null);
    }

    private void onLoadDelay() {
        getLoaderManager().initLoader(0, null, this);       
    }

    private void delayThread() {
        new Thread() {
            public void run() {
                longTimeMethod();
                handler.sendEmptyMessage(0);
            }
        }.start();
    }

    private void longTimeMethod() {
        try {
            Thread.sleep(12000);
        } catch (InterruptedException e) {
            Log.e("tag", e.getMessage());
        }
    }   
}

Can anyone let me know why this might be happening, or at least steer me in the right direction? Thanks!

  • 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-30T02:35:46+00:00Added an answer on May 30, 2026 at 2:35 am

    Unless you were stalling the main thread, making a new thread and telling it to sleep wouldn’t really solve anything.

    I can’t really say what exactly might be wrong, but it sounds like you might need to refresh your data. To test you could try to make a button with an OnClickListener which refreshes the data content, and re-pull it from the database.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is

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.