0
我的問題是我運行一個方法進入線程和30秒後我將顯示alertdialog並單擊alertdialog的ok按鈕我將停止當前線程,但問題是線程不停止,以下是我的代碼和對不起對於英語不好交際停止當前線程問題
public class CountDownTimerActivity extends Activity implements Runnable {
Thread t;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = new Thread(this);
t.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
myTimer.start();
mDeclaration();
myTimer.cancel();
}
private CountDownTimer myTimer = new CountDownTimer(30000, 1000) {
// This will give you 30 sec timer with each tick at 1 second
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
t.interrupt();
//t.stop();
AlertDialog.Builder alert = new AlertDialog.Builder(
CountDownTimerActivity.this);
alert.setMessage("Loading...");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.show();
}
};
public void mDeclaration() {
for (int i = 0; i < 100000; i++) {
System.out.println("Printing OK" + i);
}
}
}
你好Sunil_Android,這是不行的。 – 2012-03-22 07:48:26