1

Today I was thinking about how Android framework works, and I'm not sure about one thing - how developer (me) should program lists to show custom data from few sources. I created few apps, but its important to me to keep my applications clean and fast as possible.

So - I have an app, for example news reader. Im using Fragments, ListFragments, custom layouts for list items and BaseAdapter for showing data in many lists and activities. Nothing new here, and nothing special. At first I download all data from webserver to sqlite in app, so Im sure about it speed and stability. And then what's next?

Should i create List items from Java Lists (List items) and then pass it to baseadapter, or I should only use way SQLite Cursor->list item? What is better to refresh list, add new items and delete them? Remember that i have my ListFragment with baseadapter in separate class.

Im not sure about it, so I clearly dont know how should i refresh and load new items to my list. I just want to keep app clean, without many 3rd party libraries (so i dont care about EndlessList or something like that).

tl;dr

How should I create list for speed purposes, when i use few sources to show data?

1 Answers1

1

I'm not sure whether I understand your full question but about the part which data source to use for an Adapter, here are my thoughts:

I think that depends on the amount of data you are dealing with. If it is sufficiently small you can keep everything in a List in memory, but you also need to be sure that the data won't grow over time.

Using a Cursor as a data source is unfortunately also not a safe option for getting around a possible "Out Of Memory" exception problem. There is a limit per query because of the implementation of the cursor which apparently loads the whole result set into memory.

So if you are dealing with a lot of data or data that potentially grows over time (like messages, user-created items), you need to have an Adapter that internally works with a data window which loads a fixed amount of items into memory at a time. That window always keeps a bunch of items in memory which can be currently viewed and quickly reached with the ListView (by scrolling up and down).

Let's say that window holds for example 200 items. When the upper / lower bound of that window is reached the Adapter needs to load the next adjacent window. You can observe that kind of behavior in the GMail app ("Loading conversations....").

I would let that data sit in the cursor and not transfer it to a list first, because you can use the cursor like a list.

Community
  • 1
  • 1
tiguchi
  • 5,392
  • 1
  • 33
  • 39