How to .release() the MediaPlayer instantiated by RingtoneManager?
android, android-mediaplayer
Solution
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.
Problem
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(); ```