Handler to act as a timer
<p>Hi I'm trying to use a handler to update my GUI every second with random information - the info isn't important just the timer. I have created several handlers and the second handler is suppose to to the job. </p>

<p>Correct me if I'm wrong here: 
Each handler is associate with one thread; i.e. the thread the handler is created in. Therefore if I create a handler in the onCreate() method it will be attached to the GUI thread; the main thread. 
So, in order to get a task/message/method to run at a given time I should use the handler.postDelayed() method. Below is a snippet of my code:</p>

<pre><code>// Button to use handler - commence when pressed 
    handler2Btn = (Button)findViewById( R.id.handler2_Btn );
    handler2Btn.setOnClickListener( new View.OnClickListener() 
    {

        @Override
        public void onClick(View v) 
        {
            new Thread()
            {
                @Override
                public void run() 
                {
                    // Create a new thread which will get the message from handler 1 and send it
                    // when the button has been clicked
                    Message msg2 = handler2.obtainMessage( 1,"New Message for Handler 2" );
                    handler2.sendMessage( msg2 );

                    // Remove any callbacks (messages pending)
                    handler2.removeCallbacks( this );
                    handler2.postDelayed( updateGUI(), 1000 );

                } // End Run

            }.start();// Start the Thread

        }// End on Click
    });
</code></pre>

<p>And the updateGUI() method which is suppose to act update the GUI and ensure the Textview assigned acts like a timer:</p>

<pre><code>private Runnable updateGUI()
{
    return new Runnable()
    {

        // Do this every second
        @Override
        public void run() 
        {
            handlerLabelTxt2.append( ""+j );
            j++;
        }

    };
}
</code></pre>

<p>But what Im getting is, when I press the button, the GUI updates but doesn't keep updating every second. The intention is to use the button to start the process but have the process continue on its on, acting like a timer. </p>

<p>Should i move the postDelayed() method into the main body of the onCreate() method? I need a bit of help here as Handlers are confusing me! </p>

<p>Thanks</p>
