Iulian Buga
Iulian Buga

Reputation: 325

Load again the SoundPool resources

So I'm working at an app that uses lots of sounds, which in the future I'm concern that I will run in memory leaks problems. My question ... is there anyway after I release all the Sound Pool resources in the on Pause method to reload them in the on Resume method? I'm asking this because when I release the sound pool resources in my first activity and go to the second activity, every time I go back to the first activity my sound pool resources are not loaded in the on Resume method.

Here's the code where buttonclick represents the sound pool:

    @Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();

    if (buttonclick != null) {  
           buttonclick.release();}

    }


@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    if (buttonclick == null){buttonclick.load(this, R.raw.buttonclick, 1);}
}   

Upvotes: 0

Views: 523

Answers (1)

serge
serge

Reputation: 1609

Looks like your buttonclick is never null so it will never reload

maybe change it to:

if (buttonclick != null){buttonclick.load(this, R.raw.buttonclick, 1);

if this doesn't work try to assign null to the reference and on resume recreate the sound pool

Upvotes: 1

Related Questions