Aug 7, 2010
I am experimenting with using a WebView to display Flash content inside my activity. Everything is working pretty well, but when the user hits the home key to put the activity into the background, the Flash content keeps running (sound keeps playing, etc)
View 2 Replies
I have noticed that both the stock Android browser and Dolphin Browser seem to avoid this problem, and properly pause the Flash content when the browsing activity is put into the background.
Ideally I would like a solution that kills the WebView completely if the activity is finishing, but pauses it otherwise (basically copying the default behavior of the browser)
Here is a simple test I put together that loads a game on Kongregate which has some background music:
I took a look at the latest source for the stock browser, and it seems to be doing something similar (calling pauseTimers/resumeTimers), although I fear the code I have been looking at is out of date, because it is calling functions that don't seem to exist anymore.
The documentation for the mobile Flash player says:
Flash Player will also automatically pause SWF playback it is not in view or the foreground application, for example when a call is received or alarm goes off, to reduce CPU utilization, battery usage and memory usage.
This seems to be working perfectly in both the stock browser and Dolphin Browser, but not in my app. Any ideas/solutions would be greatly appreciated!
Update: Here is the function we ended up adding to our activity to get this to work. We call it with "onPause" in the activity's onPause function and "onResume" in the activity's onResume function: