package thread.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.content.Context;
import android.widget.Toast;
public class thread_test extends Activity {
private Context con = this;
/** Called when the activity is first created. */
private Thread thread;
private final Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
thread = new Thread(null, doBackgroundProcessing, "Background");
thread.start();
}
private Runnable doBackgroundProcessing = new Runnable(){
public void run(){
handler.post(doUpdateUI);
}
};
private Runnable doUpdateUI = new Runnable(){
public void run(){
Context context = getApplicationContext();
String str = "";
int duration = Toast.LENGTH_SHORT;
int time = 0;
//수정한 코드 부분 시작
while(true){
str = String.format("%d초 토스트입니다.", time);
Toast.makeText(context, str, duration).show();
try {
thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
time = time + 5;
//수정한 코드 부분 끝
}
}
};
@Override
public void onDestroy(){
thread = null;
}
}
책에서 주어지는 에제를 조금 수정했습니다. whie문으로 5초마다 출력하게 해주게 수정했습니다. 그런데 Toast가 한번도 출력이 안되네요.
무엇이 문제일까요 ㅜㅜ



