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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:10:44+00:00 2026-06-03T22:10:44+00:00

I have a Content Provider for a SQLite database that has multiple tables and

  • 0

I have a Content Provider for a SQLite database that has multiple tables and uses URIs like so:

Uri.parse("content://" + AUTHORITY + "/" + TABLE_NAME);

This seems to be the standard pattern, with 1 URI to 1 database table, along with 1 CONTENT_TYPE for all rows, and 1 for a single row.

However, I have a need to have URIs for subsets of table data. It doesn’t make sense to me currently to add a ton of additional tables to my database. It sure seems like the content provider is designed to handle this, I just can’t see it. Basically I want to have a URI that points to a query instead of a table. Hope that makes sense.

  • 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-03T22:10:46+00:00Added an answer on June 3, 2026 at 10:10 pm

    You just need to add wherever new URIs needed by your application then modify the query method of your content provider:

    public class ExampleProvider extends ContentProvider {
    
        private static final UriMatcher sUriMatcher;
    
    
        sUriMatcher.addURI("com.example.app.provider", "table3", 1);
        sUriMatcher.addURI("com.example.app.provider", "table3/#", 2);
        sUriMatcher.addURI("com.example.app.provider", "table3/customquery", 3);
    
    public Cursor query(
        Uri uri,
        String[] projection,
        String selection,
        String[] selectionArgs,
        String sortOrder) {
    
        switch (sUriMatcher.match(uri)) {
    
    
            // If the incoming URI was for all of table3
            case 1:
    
                if (TextUtils.isEmpty(sortOrder)) sortOrder = "_ID ASC";
                break;
    
            // If the incoming URI was for a single row
            case 2:
    
                /*
                 * Because this URI was for a single row, the _ID value part is
                 * present. Get the last path segment from the URI; this is the _ID value.
                 * Then, append the value to the WHERE clause for the query
                 */
                selection = selection + "_ID = " uri.getLastPathSegment();
                break;
            case 3:
                 // handle your custom query here
    
                 break;
    
        }
        // call the code to actually do the query
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own custom Content Provider that loads a database which contains the
I have an Android app that has a Content Provider with an SQLiteDatabase implementation.
I have content management system application that uses a polymorphic tree table as the
I have a service running that contains an SQLite DB and a Content Observer
I have a listview which populates its content from SQLite Database. Here's my code:
I have written my content provider supposed to wrap access to 2 tables in
I have an android app that maintains a local SQLite database of different geographic
I am developing application that uses shared preferences and content provider. But everytime I
I have a SQLite database with several (small) images that I want to be
can we have content text directly in <div>text content</div> or it should be like

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.