How do I pause Flash content in an Android WebView when my activity isn't visible?

前端 未结 2 1855
小鲜肉
小鲜肉 2020-11-28 10:22

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 activi

相关标签:
2条回答
  • 2020-11-28 10:27
    @Override
    protected void onPause() {
        super.onPause();
        this.callHiddenWebViewMethod("onPause");
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        this.callHiddenWebViewMethod("onResume");
    }
    

    This is how you call it in your activity... Works like a charm.

    0 讨论(0)
  • 2020-11-28 10:30

    I don't see where you see that BrowserActivity or anything is calling pauseTimers(). I do see where onPause() for BrowserActivity eventually routes to onPause() of WebView. However, onPause() of WebView has the @hide annotation and so is not part of the SDK. Off the cuff, it would seem like onPause() is what you want, given the comment:

    Call this to pause any extra processing associated with this view and its associated DOM/plugins/javascript/etc. For example, if the view is taken offscreen, this could be called to reduce unnecessary CPU and/or network traffic. When the view is again "active", call onResume().

    Note the reference to "plugins", which is not mentioned in the pauseTimers() documentation.

    I'd try using reflection to see if onPause() (and later onResume(), when you want stuff to start up again) does what you need. If it does, please post an issue to b.android.com about this, asking them to add these methods (or equivalents) to the SDK. Your requirement seems like it will be a common one, and a solution that goes past the SDK is not a good solution.

    0 讨论(0)
提交回复
热议问题