I have a cordova app that needs to perform some actions when the app is put in the background (either user goes to the home screen or switches to another app). The app connects to a serial device plugged into USB port and it needs to close the serial connection when the user backgrounds the app. The disocnnection operation typically takes 200 or 300 milliseconds to complete.
I am using the pause
listener as per the cordova docs for this:
window.document.addEventListener('pause', onPause, false);
The serial disconnection operation isn't working though and it seems to be because it's taking too long and Android isn't allowing it to complete.
How can this be accomplished? This is a cordova app but currently the only target platform is Android.