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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:27:01+00:00 2026-05-25T16:27:01+00:00

I am using a SQLite database on an Android application and the getAll method

  • 0

I am using a SQLite database on an Android application and the getAll method that I have written takes too much time in my opinion.

This is the code I’m talking about:

public static List<Feed> getAll(Context context) {
        List<Feed> feeds = new ArrayList<Feed>();
        Uri allFeeds = Uri.parse(ContentProvidersUris.URL_CONTENT_PROVIDER_FEED);

        long startQuery = BenchmarkUtils.start();
        Cursor c = context.getContentResolver().query(allFeeds, null, null, null, "title desc");

        long startCursor = BenchmarkUtils.start();
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            long startInsideCursor = BenchmarkUtils.start();

            Feed feed = new Feed();
            feed.setContent(c.getString(c.getColumnIndex(FeedsProvider.COL_WEBVIEW_CONTENT)));
            feed.setDate(c.getString(c.getColumnIndex(FeedsProvider.COL_PUB_DATE)));
            feed.setDescription(c.getString(c.getColumnIndex(FeedsProvider.COL_DESCRIPTION)));
            feed.setName(c.getString(c.getColumnIndex(FeedsProvider.COL_FEED_NAME)));

            Log.d(TAG, "This loop  cursor iteration took : " + BenchmarkUtils.stop(startInsideCursor) + " ms.");
        }

        Log.d(TAG, "Looping through the ENTIRE Cursor took: " + BenchmarkUtils.stop(startCursor) + " ms.");


        return feeds;
}

As you can see I am also measuring the time taken by this loop at each iteration and it turns out that it takes an average time of 1800 ms (on a Nexus S). I find that this is a lot of time. And what I don’t understand is that most of this time is spent on the first iteration as shown in the logs:

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 1726 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 2 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 2 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 2 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 0 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 5 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 1 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 1 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 5 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 1 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 1 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 1 ms.

D/FeedsProviderHelper( 5800): Looping through the ENTIRE Cursor took:
1770 ms.

So my questions are:

Is it normal? If yes, why? If not, what am I doing wrong? Any faster way to do a selectAll against the SQLite database?

Thanks!

EDIT

I took the getColumnIndex calls out of the loop as @superfell suggested, and now I am running the getAll method at an average 1500ms. It is faster but not fast enough in my opinion (again)!

  • 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-25T16:27:01+00:00Added an answer on May 25, 2026 at 4:27 pm

    Is it normal?

    Sure.

    If yes, why?

    Disk I/O is expensive, particularly on flash. The query itself is executing on your first real request against the Cursor, which is why your first “iteration” is taking substantially longer.

    Any faster way to do a selectAll against the SQLite database?

    First, you’re not doing a “selectAll” against a SQLite database. You’re doing a “selectAll” against a content provider.

    Use Traceview to determine precisely where your time is being taken up, and tune your application accordingly. For example, you might find that it makes more sense to not copy data from a Cursor into a list of POJOs in the first place.

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

Sidebar

Related Questions

I have an android application using an SQLite database. I open the database when
I have a database file that is generated on a PC using Sqlite. This
I'm using SQLite in an Android application. In all of my tables I have
I started using a SQLite database in my android application. Very simple to use
I am using Android 2.1 SDK, the application reads from the Sqlite database, a
I have an SQLite database within my Android application, which stores dates as integers.
I'm working on an Android application that stores data in a SQLite database. My
I'm developing an Android application that makes a Query using Activity.managedQuery() , which takes
I have an android application with a SQLite database and I am trying to
I am using the SQLite database and have the following persistent class (simplified): public

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.