android webview ZoomButtonsController 导致android.view.WindowLeaked 问题彻底解决


解决方案

@Override
    public void finish() {
        ViewGroup view = (ViewGroup) getWindow().getDecorView();
        view.removeAllViews();
        super.finish();
    }

附上webview加载html代码

package com.xuecheyi.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.xuecheyi.BaseActivity;
import com.xuecheyi.mb.R;
import com.xuecheyi.utils.Constant;
import com.xuecheyi.views.TitleManager;

import org.json.JSONObject;

/**
 * 创建者     涂文远
 * 创建时间   2016/10/26 14:43
 * 描述	      ${TODO}
 * 

* 更新者 $Author$ * 更新时间 $Date$ * 更新描述 ${TODO} */ public class LoadHtmlActivity extends BaseActivity { private WebView mWv; private String webUrl ="http://mb.xuecheyi.com/app/xc_news.html?newsId=15617"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_load_html); findViews(); init(); setListener(); } @Override public void onRecvData(String type, JSONObject response) { } @Override public void findViews() { mWv = (WebView) findViewById(R.id.wv_content); } int newsId = 0; @Override public void init() { String title = getIntent().getStringExtra("title"); int flag = getIntent().getIntExtra("flag",0); TitleManager.showTitle(this, title, R.drawable.nav_backarrow, "返回", null, 0, null, null); dialog.show();//加载中对话框显示 mWv.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(webUrl); return true; } }); mWv.setWebChromeClient(new MyWebChromeClient()); WebSettings settings = mWv.getSettings(); settings.setJavaScriptEnabled(true); settings.setLoadsImagesAutomatically(true); //支持自动加载图片 settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setUseWideViewPort(true);//设置此属性,可任意比例缩放 settings.setLoadWithOverviewMode(true); settings.setBuiltInZoomControls(true); settings.setSupportZoom(true); mWv.loadUrl(webUrl); } private class MyWebChromeClient extends WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) {//进度100代表webview加载完成 dialog.dismiss(); } super.onProgressChanged(view, newProgress); } } @Override public void setListener() { } @Override public void onClick(View v) { } public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWv.canGoBack()) { mWv.goBack(); return true; } return super.onKeyDown(keyCode, event); } @Override protected void onDestroy() { super.onDestroy(); mWv.destroy(); mWv = null; } @Override public void finish() { ViewGroup view = (ViewGroup) getWindow().getDecorView(); view.removeAllViews(); super.finish(); } }



你可能感兴趣的:(Android)