We know that Android UI or views can be touch from Main thread only , but if we want to update some UI from background or separate thread then we have to use one of the following way :-
AsyncTask has 4 override methods that are onPreExecute(), doInBackGround(),onProgressUpdate() and onPostExecute() where doInBackground() runs in background thread so we can't touch GUI but other three methods except doInBackground() runs in main thread so you can touch or update your UI here like update progress bar or some changes in views.
Handler is light-weight method to touch main UI from background thread. Handler is just used to obtain message ,send message and then handle message.
runOnUiThread runs in separate thread but sends a message to the UI event queue to update UI.
View's onPost() method accepts a Runnable and causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.This method can be invoked from outside of the UI thread only when this View is attached to a window.
0 Comment(s)