1

If an app has a local database that contains a large number of rows (I'm thinking hundreds or thousands of rows, but let's say a million or billion for the sake of argument), will returning all rows from a sql query to a cursor and using that to populate a ListView negatively affect performance?

Note that (1) I'm not talking about returning all columns, which is discussed here:

Also (2), I'm not talking about performance issues related to creating too many views. I understand the importance of recycling views as is discussed here:

And (3), I'm not talking about getting data from a remote server where a slow network is a concern. The app has it's own local database.

So basically I'm asking if the cursor adaptor has anything built in to continue querying the database or does it return all the data at once. That is, should I just return, say, 100 rows at a time and then requery the database for the next 100 rows when the user scrolls to the last row?

In my particular case, I am making messaging app that saves a history of all previously sent messages. Users can view all sent messages in a ListView.

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • What adapter are you using? – pskink Jan 06 '15 at 23:22
  • So you can use a specialized AbstractWindowedCursor that only keeps small CursorWindow to minimize the memory used – pskink Jan 06 '15 at 23:30
  • 1
    i recommended you the RecyclerView that provided limited window into a large data set.End look for endless recycler view. This is an endless recycler scroll listener thats when you arrived at the end you load more data https://gist.github.com/ssinss/e06f12ef66c51252563e#file-endlessrecycleronscrolllistener-java – Panayiotis Irakleous Jan 06 '15 at 23:39
  • @PanayiotisIrakleous type of view has little to do with that, ListView or RecyclerView are pretty much the same, what is important, is the adapter mapping the data to the view – pskink Jan 06 '15 at 23:53

1 Answers1

0

Please go through this link (Answer) to know some of the possible performance issues trying to fetch huge number of rows from a table.

Android SQLite and huge data sets

Also, i would recommend to retrieve the results in parts and use cursorjoiner later. Here is a nice example on how to use it.

http://chariotsolutions.com/blog/post/android-advanced-cursors/

Community
  • 1
  • 1
Prem
  • 4,823
  • 4
  • 31
  • 63
  • CursorJoiner has no use here: probably OP could use MergeCursor but when his db is really huge it has no use here as well, the only solution is a custom AbstractWindowedCursor with a small fixed size CursorWindow so that the db size doesn't matter – pskink Jan 07 '15 at 07:50