EmilyR EmilyR - 1 year ago 122
Android Question

MediaPlayer is stopping the sound when activity goes to background

[EDITED] My app is basically a

that each row (position) play a sound that is playing in loop until the same position is pressed again.

I create each sound by
and stop all of them on
of activity (in order to if the activity is destroyed - by pressing back button for instance, all sounds be sttoped).

The problem is: this works very well (I tried for 5 hours continously) on a device with API 16. But on my other device (tablet API 22) when the home button is pressed the sound is immediately turned off, however the same does not occurred on emulator with API 22 also.

Now I'm insecure about my app. I don't know if my app is wrong, if the emulator is or if my device is. :( Anyone already had the same behavior with sounds on app? Anyone knows if has any configuration on tablet with API 22 that can produce this behavior? And mostly how I fix this?

NOTE - I don't want to use service 'cause like I said that way was working well and with service I had some problems with index of my array that store the positions already pressed.


Answer Source

After so many hours struggling with this stupid question and wondering why my tablet had a behavior different of emulator, I finally found the answer, a simple answer.

My tablet was setted to don't keep activities on developer options, then when the home button was pressed the activity was destroyed and all sounds turned off. It was just uncheck this option and now everything works.

If anyone have the same problem can be this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download