关于在Dialog中使用webview,关闭时释放资源的问题

今天在弄奖励广告,发现退出的时候报错,释放serviceConnection的问题

看了几个帖子,发现说webview中如果要调用了setJavaScriptEnabled很容易出现这种情况,建议webview动态添加

看的几个帖子,先记录下

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

 

关于webview的入门帖

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

 

关于webview的内存优化

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

 

1.webview最好要用动态addview,不要直接放布局文件里

 

2.关闭Activity的时候要做这些

if( mWebview != null ){

mWebview.clearHistory();

mWebview.clearCache(true);

mWebview.freeMemory();

//mWebview.pauseTimers();//这个要跟resumeTimers()配对

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

       if (parent != null) {

           parent.removeView(mWebview);

       }

       mWebview.removeAllViews();

       mWebview.destroy();

       mWebview = null;

}

if(mAdDialog != null){

mAdDialog.dismiss();

}

猜你喜欢

转载自icesort.iteye.com/blog/2388372
今日推荐