关于在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();

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值