I have a specific situation, that is application specific that needs to be handled. My app is an ionic video surveillance app, that uses cordova for various plugins. It displays streaming JPEG images as one part of its function.
The scenarios I need to handle:
- If the app goes into background, it needs to clear up video resources, that results in stopping of video streams
- If the app is running in multi-window mode (Android 7.0+), it needs to run side by side another app in split window mode, even if the user is interacting with the other app.
- If the app is running in multi-window mode and the user actually switches it out of the view, it needs to clear up video resources
That being said, here are the following predicaments:
Today, browser apps don't get
onStop()
as a callback. We only getonPause()
. This causes a problem when running in multi-window, because the moment the user taps on the other app, my app gets anonPause()
and thinks its going into the background and clears up video resources. Obviously, this is undesirable and the viewer wants the video playback to continue (not streaming video but streaming images, so we don't really have a PIP video player situation here)There is no way, in JS land, to detect multi-window mode
According to the multi-window docs, it is now necessary to differentiate between stop()
and pause()
(and as a corollary, resume()
and start()
) for user experiences like playing of videos.
Given my specific requirements sighted above, I have arrived at the following solution:
I've developed a plugin that lets me trap
onStop()
andonStart()
and multi-window state (as a result of another related question I asked on SO a few days ago)My approach therefore, is if I am running on Android, I will not trap the browser
pause
andresume
events and only rely ononStop()
andonStart()
(simplifies the process of not having two callbacks for one event, both pause and stop/ resume and start)I've been testing situations on my android app on when
onPause()
is called and whenonStop()
is called. It seems to me they are always called together. I've read this may not be true in the case of anActivityDialog
. Based on the description there, that situation seems fine for my app as I don't need to clean up video resources.
Does anyone see a problem with this approach -- that is, don't trap onPause()
browser event if running on android, use cordova onStop()
instead? While I've tested, I might be missing something obvious that others might like to advise me on.
It is critical that my app is able to free video resources when the app actually moves to the background and its UI is not displayed (because due to some browser issues, it results in big leaks, otherwise) and hence it is important I don't miss an event. Therefore I'd like to make sure that ditching onPause()
for onStop()
doesn't result in a missed situation. I also need to support users running Android 4.2 & 4.4 for which I use the now defunct crosswalk library, so I really need to make sure by adopting this approach, I'm not going for a solution that will only work on modern systems.