0

I made an android app that plays the mario sound when you jump. It works fine (sort of), but when I close it, it still works. I tried using the onDestroy method, but it dosen't seem to delete the objects I created or something...

here is the code. http://pastebin.com/GCkrBkv9

Nathvi
  • 196
  • 1
  • 6
  • 14

1 Answers1

1

Try putting your code to stop the playing inside onPause() instead of onDestroy() like so:

@Override
public void onPause() {
        super.onPause();
        sp.stop(jump);
        sp.release();
}

It's quite possible that the activity is not yet destroyed and just sent to the background, so onDestroy() is not yet called even if you "close" the app.

Krauxe
  • 6,058
  • 2
  • 24
  • 22
  • 1
    `onDestroy()` is not always called immediately when the app goes to the background. It will only be called when the system tries to free up memory and eventually destroying your app activity, or if you explicitly call `finish()` on the activity. – Krauxe May 19 '13 at 07:21
  • 1
    Refer to this thread : http://stackoverflow.com/q/4732184/693752 to properly close an android app. – Snicolas May 19 '13 at 07:21