0

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.

d512
  • 32,267
  • 28
  • 81
  • 107
  • Based on research alone, you may want to take a similar approach as [Relying on onStop() instead of onPause() for image streaming ionic-webview/cordova apps](https://stackoverflow.com/q/51949440/295004) – Morrison Chang Sep 06 '22 at 03:04
  • @MorrisonChang thanks for the info. The poster doesn't seem to mention having issues related to how much time the app is given to perform cleanup tasks when the going into the background. They seem to be more focused on solving issues related to multi-window apps. – d512 Sep 06 '22 at 18:03

0 Answers0