About using webview in Dialog, the problem of releasing resources when closing

Today I was working on rewarding ads, and found that I reported an error when I exited, and the problem of releasing the serviceConnection

After reading a few posts, I found that this is easy to happen if setJavaScriptEnabled is called in webview. It is recommended that webview dynamically add

A few posts I read, record them first

http://blog.csdn.net/lxd_Android/article/details/56022088?locationNum=1&fps=1

http://blog.csdn.net/shareus/article/details/51742799

http://blog.csdn.net/qq_16318981/article/details/45362399

http://blog.csdn.net/l_215851356/article/details/50827584

 

Introduction to webview

http://blog.csdn.net/carson_ho/article/details/52693322

 

Memory optimization for webview

http://www.jianshu.com/p/c2412918b2b5

 

1. Webview is best to use dynamic addview, not directly in the layout file

 

2. Do these when closing the Activity

if( mWebview != null ){

mWebview.clearHistory();

mWebview.clearCache(true);

mWebview.freeMemory();

//mWebview.pauseTimers();//This should be paired with resumeTimers()

 

ViewGroup parent = (ViewGroup) mWebview.getParent();

       if (parent != null) {

           parent.removeView(mWebview);

       }

       mWebview.removeAllViews();

       mWebview.destroy();

 

       mWebview = null;

}

 

if(mAdDialog != null){

mAdDialog.dismiss();

}

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326148040&siteId=291194637