嗨,我正在工作的自定義吐司,我能夠做到這一點,但之後,當我移動到下一個活動線程正在運行或活動的回活動,所以我應該怎麼做做移除該線程或停止此線程。刪除吐司,也摧毀或強制停止線程
我的代碼如下:
public void customToast(int x, int y, String str) {
if (Util.tipson == true) {
toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, x, y);
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
toastView = li.inflate(R.layout.toastlayout, null);
toast.setView(toastView);
TextView text = (TextView) toastView.findViewById(R.id.text);
text.setText(str);
// toast.show();
fireLongToast();
}
}
private void fireLongToast() {
t = new Thread() {
public void run() {
int count = 0;
try {
while (true && count < 40) {
try {
toast.show();
sleep(100);
count++;
} catch (Exception e) {
// TODO: handle exception
}
// do some logic that breaks out of the while loop
}
toast = null;
toastView = null;
} catch (Exception e) {
Log.e("LongToast", "", e);
}
}
};
t.start();
}
thanx for reply,我完成了活動,但它不能阻止thred。 – 2012-02-13 11:29:41
在你創建的線程上調用stop() – Ruuhkis 2012-02-13 11:51:10