This is one way of doing it (as long as simHandler was created on UI 
thread).

However, this is too much work.

Just call simHandler.postDelayed on the simHandler itself; no need to 
create a separate thread:
See documentation here:
https://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable,
 
long)


On Monday, February 4, 2013 11:59:10 AM UTC-5, dashman wrote:
>
> I'd like to send messages to the main UI thread every second.
>
> This is what I did.
>
> When I need to start to send messages - I create a Thread
> from the Activity instance. this is what the thread run() method looks 
> like:
>
>         public void run()
>         {
>             try
>             {
>                 while ( !this.isInterrupted() )
>                 {
>                     android.os.Message msg = android.os.Message.obtain( 
> simHandler, 0, simulator );
>
>                     simHandler.sendMessage(msg);
>                 
>                     this.sleep( 1000 );
>                 }
>             }
>             catch ( Exception e )
>             {
>             }
>         }
>
>
> then i send a message to a handler - because I want to do the
> work in the UI thread.
>
> right way?
>
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to