zoro
zoro

Reputation: 3

How to store large list items to get maximum speed and efficiency

I am creating an app in Android and I have a large number of string data, lets way 10,000 or more words (items), I want to display it in a list view. My question is where should I put my (source) data

  1. String Array in Xml file
  2. In DB (then i have to place an external DB)
  3. Reading data from a simple text file, CSV etc

Here my only concern is speed, which way is faster and why.

Note: I am currently placing data in Xml as string array and getting it in Array in activity, but it is slow it takes few sec/moments to load data from xml but only for the first time.

Upvotes: 0

Views: 419

Answers (1)

zennon
zennon

Reputation: 1090

Execute the code to parse/load content form json/db in a AsyncTask for more speed. I load 5000 rows with ~ 400 chars per row. It takes without AsyncTask much longer.

    private class YourTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... s) {

            //Here you have to make the loading / parsing tasks
            //Don't call any UI actions here. For example a Toast.show() this will couse Exceptions
            // UI stuff you have to make in onPostExecute method

        }

        @Override
        protected void onPreExecute() {
            // This method will called during doInBackground is in process
            // Here you can for example show a ProgressDialog
        }

        @Override
        protected void onPostExecute(Long result) {
            // onPostExecute is called when doInBackground finished
            // Here you can for example fill your Listview with the content loaded in doInBackground method

        }

}

To execute you just have to call:

new YourTask().execute("");

Here you can learn more about AsyncTasks:

AsyncTask developer Guide

Upvotes: 2

Related Questions