Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to touch UI from background or seperate thread ?

    • 0
    • 2
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 222
    Comment on it

    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 :-

    1. 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.

    2. 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.

    3. runOnUiThread runs in separate thread but sends a message to the UI event queue to update UI.

    4. 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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: