java - How to pass data from separate thread class to activity in Android -


i'm android n00b bare me.

i'm trying analyze audio using audiorecord in class. problem have no idea if route i'm going try , thread separate process correct. want listen process in main ui thread , keep updating text box based on data in thread.

this have far:

//recordactivity.java [...] public class recordactivity extends activity {     final handler mhandler = new handler();     final runnable mupdateresults = new runnable() {         public void run() {             updateresultsinui();         }     };     recordthread t = new recordthread();  private onclicklistener mclicklistener = new onclicklistener() {    public void onclick(view v) {     t.start();    } }  //recordthread.java public class recorderthread extends thread { [...]  @override public void run() { [...audio process code...] } 

is there way post data recordthread class recordactivity class? there way connect handler using 2 different .java files?

also, correct way go this? should using asynctask instead?

pass mhandler parameter constructor of recordthread class, , use mhandler.obtainmessage( ... ).sendtotarget() pass data activity class

on recordactivity class, declare , use handler as:

private final handler mhandler = new handler() {     @override     public void handlemessage(message msg) {     } 

then dependes on how called obtainmessage(), if used, example, obtainmessage(int what, int arg1, int arg2) can access these using msg.what, msg.arg1, , msg.arg2.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -