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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:04:44+00:00 2026-06-18T12:04:44+00:00

I’m not very experienced with Android and Java in general, so my terms may

  • 0

I’m not very experienced with Android and Java in general, so my terms may be wrong. Sorry for that.

Any way. I have a ListActivity which gets the data from a LoaderManager. LoaderManager uses ContentProvider https://github.com/jakenjarvis/Android-OrmLiteContentProvider.

Everything is working well when the data is fetched using the contentUri (net.mydomain.app.listitems), which is defined pretty much the same way as in the example setup. But I needed data from a join query and added a URI (net.mydomain.app.listitems/items_joined) for that query. The uri is defined in the Contract class and named as itemsJoinedUri. When using this URI the list in the view is not updated when new data is inserted to the table.

In my ContentProvider class’s onQuery method I do a custom query if the “pattern code” matches to the itemsJoinedUri. Other vice I pass the work to the super method.

public class DataProvider extends OrmLiteSimpleContentProvider<DatabaseHelper> {

    @Override
    protected Class<DatabaseHelper> getHelperClass() {
        return DatabaseHelper.class;
    }

    @Override
    public boolean onCreate() {
        Controller = new MatcherController()
            .add(ListItem.class, SubType.Directory, "", Contract.ListItem.CONTENT_URI_PATTERN_MANY)
            .add(ListItem.class, SubType.Item, "#", Contract.ListItem.CONTENT_URI_PATTERN_ONE)
            .add(ListItem.class, SubType.Directory, "items_joined", Contract.ListItem.CONTENT_URI_PATTERN_WITH_ITEMS_JOINED)
            .initialize();
        return true;
    }

    @Override
    public Cursor onQuery(DatabaseHelper helper, MatcherPattern target, QueryParameters parameter) {
        Cursor result = null;
        //SQLiteQueryBuilder builder = new SQLiteQueryBuilder();

        switch(target.getPatternCode()) {
        case 310:
            String MY_QUERY = "SELECT items.name as name, listitems._id as _id FROM listitems INNER JOIN items ON items._id = listitems.item_id WHERE list_id = ?";
            SQLiteDatabase db = helper.getReadableDatabase();
            result = db.rawQuery(MY_QUERY, parameter.getSelectionArgs());
            break;
        default:
            result = super.onQuery(helper, target, parameter);
            break;
        }
        return result;
    }
}

My Contract implementation for the relevant part:

public class Contract {
    public static final String DATABASE_NAME = "mydatabase.db";
    public static final int DATABASE_VERSION = 1;

    public static final String AUTHORITY = "net.mydomain.app";
    .
    .
    .
    public static class ListItem implements BaseColumns {
        public static final String TABLENAME = "listitems";
        public static final String CONTENT_URI_PATH = TABLENAME;
        public static final String MIMETYPE_TYPE = TABLENAME;
        public static final String MIMETYPE_NAME = AUTHORITY + ".provider";

        // field info
        public static final String ITEM = "item_id";
        public static final String LIST = "list_id";
        public static final String QUANTITY = "quantity";

        // content uri pattern code
        public static final int CONTENT_URI_PATTERN_MANY = 300;
        public static final int CONTENT_URI_PATTERN_ONE = 301;
        public static final int CONTENT_URI_PATTERN_WITH_ITEMS_JOINED = 310;

        // Refer to activity.
        public static final Uri contentUri = new Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(AUTHORITY)
            .appendPath(CONTENT_URI_PATH)
            .build();

        public static final Uri itemsJoinedUri = new Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(AUTHORITY)
            .appendPath(CONTENT_URI_PATH)
            .appendPath("items_joined")
            .build();
    }
}

The ListActivity’s onCreateLoader methods are here. The one which I would like to use but which is not updating the list correctly is commented out.

//  @Override
//  public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
//      String[] selectArgs = { "" + list_id };
//      Uri baseUri = Contract.ListItem.itemsJoinedUri;
//      return new CursorLoader(this, baseUri, null, null, selectArgs, null);
//  }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
        String select = "( " + Contract.ListItem.LIST + " = 2 )";
        Uri baseUri = Contract.ListItem.contentUri;
        String[] projection = new String[] {
                Contract.ListItem._ID,
                Contract.ListItem.LIST
        };
        return new CursorLoader(this, baseUri, projection, select, null, null);
    }

New items to the list are inserted in a different Activity using a code getContentResolver().insert(Contract.ListItem.contentUri, values);. That Activity is one step deeper in the hierarchy than the ListActivity so I can get back to the ListActivity with the back button, and that is when I see that the list has not updated.

So the data is inserted using the contentUri but read using my own itemsJoinedUri. Could that be the issue here?

EDIT

I added a simple clicklistener to delete a row from the list. That uses the contentUri and the list is automatically updated after the delete. So I guess the issue for list not being updated when moving back to the list from another Activity might relate to faulty implementation of the life cycle of the ListActivity.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    String[] args = { "" + id};
    getContentResolver().delete(Contract.ListItem.contentUri, "_id = ?", args);
}
  • 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-18T12:04:45+00:00Added an answer on June 18, 2026 at 12:04 pm

    The issue was in the life cycle management. I didn’t have proper onRestart() implementation. After adding this everything works.

    @Override
    public void onRestart() {
        super.onRestart();
        getLoaderManager().getLoader(0).forceLoad();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
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
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I need a function that will clean a strings' special characters. I do NOT
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.