如果我启用每秒刷新线程,我制作了一个音乐播放器,每次尝试关闭它时都会崩溃(刷新是为了更新歌曲的经过时间和进度条)。这是代码:
/**
* Background Runnable thread
* */
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
long totalDuration = mp.getDuration();
long currentDuration = mp.getCurrentPosition();
// Displaying Total Duration time
songTotalDurationLabel.setText(""+utils.milliSecondsToTimer(totalDuration));
// Displaying time completed playing
songCurrentDurationLabel.setText(""+utils.milliSecondsToTimer(currentDuration));
// Updating progress bar
int progress = (int)(utils.getProgressPercentage(currentDuration, totalDuration));
//Log.d("Progress", ""+progress);
songProgressBar.setProgress(progress);
// Running this thread after 100 milliseconds
mHandler.postDelayed(this, 100); //this line is causing errors
}
};
这一切都在活动中再次起作用,但是一旦我按下后退按钮,它就会崩溃。有任何想法吗?谢谢