Difference between thread / runnable, handler, runonuithread, asynctask

I started learning Android programming and am working on a small game. I heard that doing background operations or updates or loading, as well as what ever happened and took a lot of time using the ui thread, use thread / runnable or asynctask instead. but I can’t do some things in threads, for example, a background connection to the database, where, since this connectivity works with the remaining handler, runonuithread, asynctask.am is very confused where to use it. I have several questions 1.handler, runonuithread - both are executed on a ui thread, thread / runnable is another thread and in an async task, the doinbackground method is executed on different threads and other methods, such as onprogressupdate, onpreexecute and onpostexecute, executed on the thread ui. correctly? if it is true,I wrote a program to connect to the database with thread / runnable, it did not work, but when I wrote it in doinbackground, it worked. my confusin is that since both of these methods work on different threads, why is this happening. 2. What is the main difference between the 4 and where they are applicable and not applicable. And also want to know what tasks only ui threads can perform. thanks in adv :)

+4
source share
2 answers

A Handler , . Activity#runOnUiThread(Runnable) - , Handler , a Runnable (. ). Handler , . , View , , , .

An AsyncTask - , (.. onPreExecute, onPostExecute ..), ( , Handler ).

+3

, !

Thread - , groovy. Java-. Java ( Android) .

Runnable - , , Thread, . , run().

- , Android Thread. .

RunOnUiThread - , a.k.a. Android! , Thread! Android , ( a.k.a. UI) , Google .

AsyncTask - ! Android. , "" "". , AsyncTask , !


AsyncTask - c00l, :

, AsyncTask . 3 ! , !

"". , , , , .

! 1

() JUST .


, , , , , , !

- , . , . , , , AsyncTask Handler, !

, , .

+2

All Articles