package com.;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
/**
* You can get the data of the View class in other threads, but you cannot modify or set the data of the View class.
*
*/
public class Main extends Activity {
TextView result = null;
EditText get = null;
Button update = null;
Handler handler;
public void onCreate(Bundle bundle) {
(bundle);
setContentView();
result = (TextView) findViewById();
update = (Button) findViewById();
get = (EditText) findViewById();
handler = new Handler() {
public void handleMessage(Message msg) {
if ( == 1) {
("after update ui "
+ ().getString("data")
+ " \nman thread : "
+ ().getName());
}
}
};
("before update ui main thread : "
+ ().toString());
(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new MyThread("my thread").start();
}
});
}
class MyThread extends Thread {
public MyThread(String name) {
super(name);
}
@Override
public void run() {
// Send messages without data
// (1);
// Send a message with attached data
Message msg = new Message();
Bundle data = new Bundle();
("data", ().toString() + " my thread: "
+ ().getName());
(data);
= 1;
(msg);
}
}
}