I have created a thread so that I can get the current position of my MediaPlayer without disturbing the UI but I seen to be getting a lot of garbage collection when the timer is running, is it normal?
Also to avoid the risk of spamming, does anyone else know a better way to display the position of a MediaPlayer which is more efficient?
private void processThread() {
final MediaPlayer MP;
MP = MediaPlayer.create(this, R.raw.sleepaway);
MP.start();
new Thread(){
public void run(){
handler.post(new Runnable(){
@Override
public void run() {
myText.setText(getTimeString(MP.getCurrentPosition()));
handler.postDelayed(this,10);
}
});
}
}.start();
}
The messages I receive about three times a second:
08-14 05:44:27.385: DEBUG/dalvikvm(32100): GC freed 10820 objects / 524656 bytes in 75ms
The thread you are creating is completely useless, just do the post(Runnable). Also, you are creating an infinite “loop” with your postDelayed().