Starting a runnable in background thread Starting a runnable in background thread multithreading multithreading

Starting a runnable in background thread


custListLoadThread = new Thread(loadRunnable);custListLoadThread.start();

You need to start the thread, not call the run() method in the current thread.


If you want to execute code on a background thread that does not do something with the UI:

    Runnable runnable = new Runnable() {        @Override        public void run() {            //your action        }    };    AsyncTask.execute(runnable);

Of course as written before you can also create a new thread (that is independent from the UI thread):

    new Thread(runnable).start();

In your example you want to update UI elements, so better use a AsyncTask (must be called from UI thread!):

    new AsyncTask<Void, Void, Void>() {        @Override        protected Void doInBackground(Void... params) {            // your async action            return null;        }        @Override        protected void onPostExecute(Void aVoid) {            // update the UI (this is executed on UI thread)            super.onPostExecute(aVoid);        }    }.execute();