我正在开发一个音乐应用程序,其中使用了SeekBar。我有一个处理SeekBar性能的方法,它运行良好。但是如果SeekBar在运动中存在内存泄漏,Log cat会显示如下:
GC_CONCURRENT freed 1692K, 34% free 10759K, paused 3ms+8ms
当进度条正在进行时,这个问题会持续出现。
我发现问题是由于动态更新TextView引起的,它用于显示歌曲的当前时长。
我应该如何解决这个问题?请帮我解决这个问题。
我的函数是:
public void seekbarProgress(){
handler.postDelayed(new Runnable() {
@Override
public void run() {
//current position of the play back
currPos = harmonyService.player.getCurrentPosition();
if(isPaused){
//if paused then stay in the current position
seekBar.setProgress(currPos);
//exiting from method... player paused, no need to update the seekbar
return;
}
//checking if player is in playing mode
if(harmonyService.player.isPlaying()){
//settting the seekbar to current positin
seekBar.setProgress(currPos);
//updating the cuurent playback time
currTime.setText(getActualDuration(""+currPos));
handler.removeCallbacks(this);
//callback the method again, wich will execute aftr 500mS
handler.postDelayed(this, 500);
}
//if not playing...
else{
//reset the seekbar
seekBar.setProgress(0);
//reset current position value
currPos = 0;
//setting the current time as 0
currTime.setText(getActualDuration(""+currPos));
Log.e("seekbarProgress()", "EXITING");
//exiting from the method
return;
}
}
}, 500);
}
""+currPos
语句会导致大量的垃圾回收。请阅读有关Java“不可变字符串”的相关资料。 - Simon