0

I've noticed a strange problem: My app uses SoundPool to play sounds. When I terminate the App with the back key while some sounds are playing, SoundPool will not work correctly the next time I start the App (even if I start another App that uses SoundPool, the sound is not working, I have to restart the device to get SoundPool working again).

I've found a solution that helps: I have to stop all playing sounds in the onDestroy() method and call then SoundPool.release().

The problem is, when the user kills the App with the task manager, onDestroy does not get called and I can not stop / release the sounds. Does anybody know

a) how I can detect that the App got killed b) use another mechanism to prevent SoundPool from not working after termination of the App

Tested on a Samsung Galaxy S Plus with Android 2.3.6

osiris81
  • 487
  • 4
  • 15
  • 1
    you can probably stop in onPause since that will be called – zapl Apr 15 '12 at 22:43
  • Actually, I do stop the sounds in onPause(), but I call SoundPool.release in onDestroy(), otherwise I'd have to reload all sounds in onResume() – osiris81 Apr 15 '12 at 22:47

1 Answers1

2

The SurfaceView has overrideable methods like surfaceCreated and surfaceDestroyed. Also instead of calling release, you should call the soundPool.stop(streamId), where the streamId is the integer returned by the soundPool.play method, if you use a wrong streamId looping sound wont stop. I had the same problem of using the streamId of another sound that I wasn't looping.

user
  • 86,916
  • 18
  • 197
  • 190