I wrote this code to try threads on Android, but it doesn't work.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread t = new Thread() {
@Override public void run() {
int i = 0;
while(true) {
i += 5;
if(i == 1000000)
break;
}
}
};
t.run();
}
I have some GUI and when thread works (i < 1000000), GUI freezes. But when thread is done (i == 1000000) everything works fine.
What's wrong?
// Sorry for my english
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…