问题
I'm getting a default Ringtone in my Activity:
remindRingtoneView = (TextView) findViewById(R.id.remind_ringtone);
remindRingtoneView.setText(RingtoneManager.getRingtone(
NewReminder.this, ringtone_uri).getTitle(
NewReminder.this));
After this line I've got a debug line in LogCat with tag = 'Ringtone' and message =
'Successfully created a local player'.
When I finished Activity and system garbage collector do it's good job I got a warn message in LogCat =
'MediaPlayer finalized without being released'.
How I can release it?
Answer is:
Ringtone remind_ringtone = RingtoneManager.getRingtone(
NewReminder.this, ringtone_uri);
remindRingtoneView.setText(remind_ringtone.getTitle(NewReminder.this));
remind_ringtone.stop();
回答1:
In your program, RingtoneManager.getRingtone
will return an object to Ringtone
class. If we consider this object to be mRingTone
, then invoking mRingTone.stop()
will release the MediaPlayer
object.
来源:https://stackoverflow.com/questions/15450255/how-to-release-the-mediaplayer-instantiated-by-ringtonemanager