android - Periodic Message in Thread -


i have activity (myactivity) , thread (mythread) , both handler allow me send message between ui thread , mycustomthread. call periodically (10sec) alive message of mythread thread myactivity. how can achieve ?

myactivity :

public void onresume() {     super.onresume();     this.thread                 = new mythread(activityhandler);     this.threadhandler  = this.thread.gethandler();      threadmessage           = this.threadhandler.obtainmessage();     threadmessage.what  = auth;     this.threadhandler.sendmessage(threadmessage); } 

mythread :

@override

public void run() {          looper.prepare();          this.threadhandler = inithandler();          this.message        = this.activityhandler.obtainmessage();         this.message.what   = connected;         activityhandler.sendmessage(this.message);          looper.loop();  }  private handler inithandler() {     return new handler() {          public void handlemessage(message msg)         {             switch(msg.what)             {                 case auth :                  {                     auth();                     break;                 }                  case alive :                 {                     sendalive();                     break;                 }             }         }     }; } 

thanks help

the correct solution depends on trying put together...

this walk through performing action on timer how use delayed post (the preferred way of executing on schedule because doesn't use thread timer). write , include why.

hope helps.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -