Android:How 到 finish/stop 线程
Android:How to finish/stop the thread
当t.stop()时应用会崩溃;
情况:我想每 2 秒(25 次)将 textview 文本保存到数组中;
t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(2000);
runOnUiThread(new Runnable() {
@Override
public void run() {
// update TextView here!
if (i < 25) {
mypDialog.setProgress(i * 4);
getRssi(iBeaconPosition, i);
i++;
} else {
finishCalibration();
}
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
您必须使用:
t.interrupt();
有关详细信息,请阅读此 link and this link;
当t.stop()时应用会崩溃; 情况:我想每 2 秒(25 次)将 textview 文本保存到数组中;
t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(2000);
runOnUiThread(new Runnable() {
@Override
public void run() {
// update TextView here!
if (i < 25) {
mypDialog.setProgress(i * 4);
getRssi(iBeaconPosition, i);
i++;
} else {
finishCalibration();
}
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
您必须使用:
t.interrupt();
有关详细信息,请阅读此 link and this link;