Software Archive
Read-only legacy content
17061 Discussions

App reload when minimized and stop sound ( Only on Android 6.0 Marshmallow )

Eberton_M_
Beginner
508 Views

Im making a one app to play audio streaming with html5.

All works fine, play in background, etc.

But on Android 6.0 Marshmallow he reload if minimized, see: https://drive.google.com/open?id=0B7_KN57XiL-xLU5kaEF1c1dTT0k

On others versions of android works like a charm, i think is some permission. Anyone have idea to solve this?

Already tried some plugins ( Native audio, Media, cordova plugin background audio, Ktzer background mode ) :(

0 Kudos
8 Replies
PaulF_IntelCorp
Employee
508 Views

What are you setting the "Target Android API" level to? Set it to 21 and build with Crosswalk (any version) to see if you get the same results.

0 Kudos
Eberton_M_
Beginner
508 Views

Hello Paul, thank you for reply.
Same problem, still have problem on  Android 6.0 Marshmallow =(

Any idea?

0 Kudos
PaulF_IntelCorp
Employee
508 Views

Eberton -- since you get the same results whether you use Crosswalk or the native webview, it must be something to do with Android 6. As you indicated earlier, it might be a permissions issue, but setting the target API level to 21 generally takes care of that problem, because it effectively tells the Android runtime that you are not yet compatible with the new permissions APIs that level 23 introduced.

Probably what's happening is Android 6 is being more aggressive about power saving and is forcing your app to "quit." Which then results in a "resume" from a cold state. I would add some code to capture entry into the pause and resume states and write some data out to see if that's what's happening (for example to console.log). You'll have to do this debugging with a built app for an accurate representation of what's going on (see https://software.intel.com/en-us/xdk/docs/intel-xdk-debug-and-test-overview#RemoteChromeDevTools). It's quite possible remote CDT could interfere with these events, in which case you may need to write some info to an on-device file (using the cordova file plugin API, write to a file in the "external SDCard" folders) and then retrieve that information after the fact.

Here are some links that will help with the pause/resume events:

Note that there are several other Android lifecycle events, as briefly described by this SO post:

Additional FYI:

Especially, the "onPause" and the "window.onunload" events may be useful to track for help in debugging this issue.

0 Kudos
Eberton_M_
Beginner
508 Views

Thanks Paul, I think I could understand what is going on.

Is this some method to prevent the pause event?

0 Kudos
PaulF_IntelCorp
Employee
508 Views

You cannot stop a pause event from within a webview, the Android OS uses that to manage device battery consumption. It can be done using special plugins, so you might have to investigate finding some plugins that allow your app to continue running in the background. A better solution would be a plugin that explictly allows a specific function to run in the background, an then the rest of your app needs to monitor the "resume" event so you can restore the rest of your app to the appropriate state, avoiding the "reset" that appears to be taking place.

It could also be that there's a "task manager" running on your Android 6, test device that's causing this to happen.

0 Kudos
Eberton_M_
Beginner
508 Views

Solved! Thank you so much Paul, you saved my life. :D

0 Kudos
PaulF_IntelCorp
Employee
508 Views

What was the solution? Please share so it can help others with the same symptoms.

0 Kudos
Malek_D_
Beginner
508 Views

Eberton M. wrote:

Solved! Thank you so much Paul, you saved my life. :D

Hi! Can you please share with us your solution ?

Thank you !

0 Kudos
Reply