我正在尝试保存片段中webview
的状态。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
try {
View view = inflater.inflate(R.layout.fragment_activity, container, false);
browser = (WebView) view.findViewById(R.id.webview);
if (browser != null) {
//browser.setWebViewClient(new WebViewClient());
if (webViewBundle == null || webViewBundle.isEmpty()) {
// browser.setWebViewClient(new WebViewClient());
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//Users will be notified in case there's an error (i.e. no internet connection)
Log.i("", "");
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
url = url;
}
public void onPageFinished(WebView view, String url) {
CookieSyncManager.getInstance().sync();
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
browser.loadUrl(url);
} else {
browser.restoreState(webViewBundle);
webViewBundle.clear();
}
}
return view;
}
catch (Exception ex)
{
ex.printStackTrace();
return null;
}
}
我正在压倒onPause
:
@Override
public void onPause() {
super.onPause();
if (browser != null && webViewBundle.isEmpty()) {
browser.saveState(webViewBundle);
}
}
我在viewPager
上有4个这样的片段
但是当片段被导航回来时,webview
会冻结。