In my app there are two activities viz A and B.
Activity A:
It has a list which displays information about an item briefly. When an item on
I followed series of steps and got the memory footprint reduced. This is what I did, instead of creating webview statically via xml I now create webview programmatically and add it to a container. Once webview is no longer needed I remove the webview from the container then I remove all views from webview and call destroy on it. Eventually memory allocated reduces.
private void releaseWebView() {
webViewContainerRelView.removeAllViews();
if(mWebView != null){
mWebView.setTag(null);
mWebView.clearHistory();
mWebView.removeAllViews();
mWebView.clearView();
mWebView.destroy();
mWebView = null;
}
}
I call releaseWebView() from onDetachedFromWindow method of Activity as below.
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
releaseWebViews();
}