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

The Archive Base Latest Questions

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

I have a custom Android ContentProvider which stores and retrieves data from a SQLite

  • 0

I have a custom Android ContentProvider which stores and retrieves data from a SQLite database.

Let’s assume one of the DB tables has an _ID column and a NAME column and a content like this:

|==========|==========|
|   _ID    |   NAME   |
|==========|==========|
|    1     |    d1    |
|    2     |    d2    |
|    3     |    d3    |
|    4     |    d4    |
|==========|==========|

This SQLite DB is kept in sync with a remote database and new data is fetched periodically over the network.
The possible operations on the table are as follows:

  1. Existing rows can be deleted
  2. New rows can be added
  3. The NAME column of existing rows can be modified

Let’s now assume that all the possible operations happen at once and, after fetching some up-to-date data from a remote server, the new content of this table has to be set as follows:

|==========|==========|
|   _ID    |   NAME   |
|==========|==========|
|    1     |    d7    |
|    3     |    d3    |
|    4     |    d6    |
|    5     |    d5    |
|==========|==========|

There can be two different approaches to do that:

  1. Query the database and check each existing rows to see if they need to be updated, then add any new rows and delete any missing rows – though this method can be a bit tricky in case we want to update the database with a pagination approach and not with a single network fetch
  2. Delete the entire table with a single DELETE SQL command and then add all the rows received from the server

On Android, I am currently implementing the second method with batch operations to maximize the performance:

final ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

// with this URI, the content provider deletes all rows
operations.add(ContentProviderOperation.newDelete(Users.CONTENT_URI).build());

final ContentValues values = new ContentValues();
values.put(ID_COLUMN, 1);
values.put(NAME_COLUMN, "d7");
values.put(ID_COLUMN, 3);
values.put(NAME_COLUMN, "d3");
values.put(ID_COLUMN, 4);
values.put(NAME_COLUMN, "d6");
values.put(ID_COLUMN, 5);
values.put(NAME_COLUMN, "d5");

operations.add(ContentProviderOperation.newInsert(Users.CONTENT_URI).withValues(values).build());

getApplicationContext().getContentResolver().applyBatch(MyContentProvider.AUTHORITY, operations);

Is this the best approach, or would method 1 (or some other method) be better in terms of performance?

EDIT: for example, taking approach 2, an overridden ContentProvider#bulkInsert which uses database transactions could speed up the batch-insert operation a lot: see this question.

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

    The best option requires proper API implementation – when you should store some db_version(int or timestamp of last update, or whatever).

    And during update server responds with data, and operation type – add, update, delete.

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

Sidebar

Related Questions

I'm working on an application which uses SQLite Database on Android.I have a custom
In android application i have a custom listview and sqlite database. I want to
I have a custom ContentProvider I use to store fixes obtained from the GPS
I have a custom ScrollView (extended android.widget.ScrollView) which I use in my layout. I
For Android, I have a custom view which I fill up with primitive shapes
I have a custom view (android) which draws a custom progress bar. I want
I have an android gridview which i'm using some custom scrolling going on in,
I have a simple android application which does search. I have a custom popup
I have a custom Android view which overrides onTouchEvent(MotionEvent) to handle horizontal scrolling of
I have to create a custom compound button bar control in Android like the

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.