Created
June 8, 2016 06:29
-
-
Save dzwillpower/b0aa4ca26cd2314223bd553d3c7a3577 to your computer and use it in GitHub Desktop.
destroy webbiew avoid memory leak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void destroyAll() { | |
for (WebView webview : mWebViews) { | |
if (webview != null) { | |
webview.onPause(); | |
webview.stopLoading(); | |
webview.setWebViewClient(null); | |
webview.removeAllViews(); | |
webview.clearHistory(); | |
webview.clearCache(true); | |
webview.destroy(); | |
ViewParent parent = webview.getParent(); | |
if (parent != null && parent instanceof ViewGroup) { | |
ViewGroup oldParent = (ViewGroup) parent; | |
oldParent.removeView(webview); | |
} | |
webview = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment