I’m trying to play a background sound in my Android application. I’m using a seperate class as a Soundmanager. And in my first activity, i start the sound and i want it to play through 2 other activitys. And in my third class i want it to stop and another sound should play.
But im having a problem stopping that sound and don’t know why. I guess it has something to do with that im using the class Context in my Soundmanager class.
Does anyone know how to make the sound stop? I’ll link my Soundmanager class becuase that is the only one that is relevant i guess. Im pretty new to programming, so please be gentle.
Soundmanager class
http://codepad.org/KJi6DZN6
Make all of your methods and class variables in
SoundManagerstatic (and pass in aContextfor the methods that require one).I would suspect that you are maybe creating a new instance of
SoundManagerin each of your Activities, which would create multiple instances ofSoundManager. Making it statically accessible will mean all Activities are modifying the same variables.Another note, I don’t think you have to have an Activity
Context, so try passing in your application’s Context viacontext.getApplicationContext(). This will avoid tying theMediaPlayerobject to any specific Activity.