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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:21:53+00:00 2026-06-14T16:21:53+00:00

I have an app that shows data from a SQLite DB and the data

  • 0

I have an app that shows data from a SQLite DB and the data changes constantly, so obviously, I thought I should use a LoaderManager to show the data.

do I read a bit about using the LoaderManager with SQLite and saw Alex Lokwood’s answer about implementing the CursorLoader and using it, and I saw the this answer about using a CursorLoader directly to an SQLite DB instead of a ContentProvider and started using commonsware’s Loaderex.

I created this class for showing the data in a ListView:

public class LandingPageActivity extends FragmentActivity implements LoaderCallbacks<Cursor> {
    ListView list;
    SimpleCursorAdapter mAdapter;

    private SQLiteCursorLoader loader = null;
    private Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_friends_and_threads);
        list = (ListView) findViewById(R.id.list);
        mContext = LandingPageActivity.this;

        mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null,
                new String[] { Properties.Title.columnName }, new int[] { android.R.id.text1 }, 0);

        list.setAdapter(mAdapter);
        getSupportLoaderManager().initLoader(0, null, this);
    }

    @Override
    public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
        Context c = mContext;
        String query = "SELECT * FROM TABLE_NAME";
        SQLiteOpenHelper db = DatabaseHelper.getDatabase();
        loader = new SQLiteCursorLoader(c, db, query, null);
        return loader;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
        mAdapter.changeCursor(arg1);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> arg0) {
        mAdapter.changeCursor(null);
    }
}

the problem starts when the database is changed from a ‘BroadcastListener’ while the activity is still running.

basically what I’m looking for is real-time observing of the database changes but it seems (also from the Android Documentation that I need to call the restartLoader function when I want to re-query the db).

is there a way to automate re-query behind the scenes?

UPDATE:

My initial thought was to create a function that restarts the loader, something like this:

public static void restartLoader(Context context){
    context.getSupportLoaderManager().restartLoader(0, null, LandingPageActivity.this);
}

but it seems crud and not the best way of doing 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-14T16:21:54+00:00Added an answer on June 14, 2026 at 4:21 pm

    the problem starts when the database is changed from a ‘BroadcastListener’ while the activity is still running… is there a way to automate re-query behind the scenes?

    Have the BroadcastReceiver use the insert(), update(), replace(), and delete() methods on SQLiteCursorLoader to modify the database. Then, the Cursor will be re-loaded automatically.

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

Sidebar

Related Questions

I have an app that reads from sqlite database, and then shows the content
I have an app that has a mapview, and it shows 20 pins (from
I have some XML data retrieved from a web service that I use to
I have android app that talks to server and syncs some data int SQLite
I want to create a app that shows data from a local db in
I have an app that shows video all the time in fullscreen mode. So
I have an app that shows a series of UIImageView s on a ScrollView
I have an iPhone app that shows a simple view (View 1) that has
I have a little iOS5 app that shows images. I click on the image
I've created an app that shows 8 buttons in coverflow using icarousel.i have to

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.