如何停止进度条,当我们停止处理程序android
问题描述:
嗨,我是新的android和在我的应用程序我使用进度条为此录音为此,当我开始录制我正在更新进度栏,这很好,在这里,当我停止录音进度没有停止它的连续更新,请帮我有人如何停止进度,当我停止录音如何停止进度条,当我们停止处理程序android
private void startRecording() {
try {
handler = new Handler();
recorderProgressBar = (ProgressBar) dialog.findViewById(R.id.recorder_progressBar);
progressStatus = 0;
// Start the lengthy operation in a background thread
thread = new Thread() {
@Override
public void run() {
while (progressStatus < 100) {
// Update the progress bar
if (handler != null) {
// Update the progress status
progressStatus += 1;
// Try to sleep the thread for 20 milliseconds
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.post(runnable);
}
}
}
};
thread.start();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
Runnable runnable = new Runnable() {
public void run() {
System.out.println("it's calling ramakrishna");
recorderProgressBar.setProgress(progressStatus);
}
};
private void stopRecording() {
//Kill Background thread
if (handler != null) {
handler.removeCallbacks(runnable);
}
}
答
您可以停止线程来代替。
private void stopRecording() {
//Kill Background thread
if (handler != null) {
handler.removeCallbacks(runnable);
}
if (thread != null) {
thread.stop();
}
}
或者你可以使用thread.interrupt()
的建议在这里:Do not use Thread.stop()。
答
定义recorderProgressBar出该方法,然后停止,如果它不为空。
OK,让我试着告诉你导致 – Krish
没有连我初始化处理程序时活动开始进度更新 – Krish
请让我知道solutiuon – Krish