Monday, 15 April 2013

how to use handlers

 A handler will be executed on the thread in which it is created.

    There are two uses of Handler
(1) to schedule messages and runnables to be executed as some point in the future

(2) to enqueue an action to be performed on a different thread than your own. 

sample code:

    private Runnable pageChangingTask = new Runnable() {
       
        @Override
        public void run() {
          //executable code write here
           
        }
    };






//this line of code will remove any of the pending task in queue.

handler.removeCallbacks(pageChangingTask);




//postDelayed method takes two arguements one runnable object and 
//  time in milliseconds.





                handler.postDelayed(pageChangingTask, 500);

No comments:

Post a Comment