Java Code Examples for android.webkit.WebView#destroy()

The following examples show how to use android.webkit.WebView#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallActivity.java    From sealrtc-android with MIT License 6 votes vote down vote up
public void destroyWebView(WebView mWebView) {
    if (mWebView != null) {
        try {
            ViewParent parent = mWebView.getParent();
            if (parent != null) {
                ((ViewGroup) parent).removeView(mWebView);
            }
            mWebView.stopLoading();
            mWebView.getSettings().setJavaScriptEnabled(false);
            mWebView.clearHistory();
            mWebView.clearView();
            mWebView.removeAllViews();

            mWebView.destroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
static final void clearWebView(WebView m) {
	if (m == null) {
		return;
	}
	if (Looper.myLooper() != Looper.getMainLooper()) {
		return;
	}
	m.loadUrl("about:blank");
	m.stopLoading();
	if (m.getHandler() != null) {
		m.getHandler().removeCallbacksAndMessages(null);
	}
	m.removeAllViews();
	ViewGroup mViewGroup = null;
	if ((mViewGroup = ((ViewGroup) m.getParent())) != null) {
		mViewGroup.removeView(m);
	}
	m.setWebChromeClient(null);
	m.setWebViewClient(null);
	m.setTag(null);
	m.clearHistory();
	m.destroy();
	m = null;
}
 
Example 3
Source File: PrivacySettingsFragment.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
private void clearCache() {
    WebView webView = new WebView(mActivity);
    webView.clearCache(true);
    webView.destroy();
    Utils.showSnackbar(mActivity, R.string.message_cache_cleared);
}
 
Example 4
Source File: BoardItemListFragment.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final String userAgent = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(getString(R.string.user_agent_pref), null);
    if (userAgent != null) {
        RequestQueueUtil.getInstance().setUserAgent(userAgent);
    } else {
        try {
            final WebView webView = new WebView(getActivity());
            final String webViewAgent = webView.getSettings().getUserAgentString();

            PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString(getString(R.string.user_agent_pref), webViewAgent).apply();
            webView.destroy();
        } catch (Exception e) {

            if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(getString(R.string.user_agent_pref), null) == null) {
                final String defaultAgent = System.getProperty("http.agent");
                PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString(getString(R.string.user_agent_pref), defaultAgent).apply();
            }
        }
    }

    if (getActivity() instanceof MimiActivity) {
        toolbar = ((MimiActivity) getActivity()).getToolbar();
    }

    rootView = inflater.inflate(R.layout.fragment_boards_list, container, false);
    errorSwitcher = rootView.findViewById(R.id.error_switcher);

    boardListAdapter = new BoardListAdapter(getActivity(), new ArrayList<>());

    final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    boardsList = rootView.findViewById(R.id.boards_list);
    boardsList.addItemDecoration(new DividerItemDecoration(boardsList.getContext(), RecyclerView.VERTICAL));
    boardsList.setLayoutManager(layoutManager);
    boardsList.setAdapter(boardListAdapter);
    boardListAdapter.setDragListener(viewHolder -> itemTouchHelper.startDrag(viewHolder));
    boardListAdapter.setOnItemLongClickListener((parent, view, position, id) -> {
        if (getActivity() != null) {
            getActivity().startActionMode(getActionMode());
        }
        return true;
    });
    return rootView;
}
 
Example 5
Source File: WebViewBitmapDecoder.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
private void countDownAndDestroy(WebView view) {
	latch.countDown();
	view.destroy();
}
 
Example 6
Source File: PrivacySettingsFragment.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
private void clearCache() {
    WebView webView = new WebView(mActivity);
    webView.clearCache(true);
    webView.destroy();
    Utils.showSnackbar(mActivity, R.string.message_cache_cleared);
}