Threading and caching are probably good ideas. If your list has only ten people (10 times in 2 Kbytes of memory, 20 kB), consider using a cached list for the user interface and update it after each download. Check out the AsyncTask class that was introduced with Android 1.5 for this. A simple code example might look something like this:
mCachedList; private void onUpdate(Location location) { DownloadTask refresh = new DownloadTask(location); refresh.execute(); } private class DownloadTask extends AsyncTask<Location, void, ArrayList<ListItem> { protected ArrayList<ListItem> doInBackground(Location... params) { final ArrayList<ListItem> refreshlist = new ArrayList<ListItem>; Location location = params[0]; sendToCloud(location); while(!done) { ListItem next = downLoadPerson(); refreshlist.add(next); } return refreshlist; } protected void onPostExecute(ArrayList<ListItem> refreshlist) { mCachedList = refreshlist; } }
Use the cached list for the user interface until the background task finishes and is updated. There are more complex things you could do to save more memory, like reusing the update list, etc., but I hope the above gives some information on how to do this in the background. Also remember to reuse the conversion on your list to avoid a lot of garbage collection on each item when scrolling through the list.
source share