package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class MainActivity extends Activity {
private TextView tv;
// Message Processor
private Handler handler;
private static final int TURNTEXT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
// setContentView(.activity_main);
("Main thread----" + ().getName());
tv = new TextView(this);
("Hello");
setContentView(tv);
// Processor
handler = new Handler() {
// handlerMessage method handles the message sent by handler
@Override
public void handleMessage(Message msg) {
(msg);
// Operation to obtain what message to send, and perform different processing methods according to the message identification
int what = ;
if (what == TURNTEXT) {
(() + "");
}
}
};
try {
//The main thread blocks 6s greater than
(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
();
}
//The run method is executed and the thread dies
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
("Child thread----"
+ ().getName());
(1000);
// Send a message what logo
(TURNTEXT);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
();
}
}
}
}).start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu);
return true;
}
}
package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class MainActivity extends Activity {
private TextView tv;
// Message Processor
private Handler handler;
private static final int TURNTEXT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
// setContentView(.activity_main);
("Main thread----" + ().getName());
tv = new TextView(this);
("Hello");
setContentView(tv);
// Processor
handler = new Handler() {
// handlerMessage method handles the message sent by handler
@Override
public void handleMessage(Message msg) {
(msg);
// Operation to obtain what message to send, and perform different processing methods according to the message identification
int what = ;
if (what == TURNTEXT) {
(() + "");
}
}
};
try {
//The main thread blocks 6s greater than
(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
();
}
//The run method is executed and the thread dies
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
("Child thread----"
+ ().getName());
(1000);
// Send a message what logo
(TURNTEXT);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
();
}
}
}
}).start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu);
return true;
}
}