我正在开发一个音乐应用程序,其中使用了 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);
}