summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/WebViewFragment.java
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-06-30 15:02:15 +0100
committerSteve Block <steveblock@google.com>2011-07-01 14:10:40 +0100
commit071970d9d64ddbeb77f9c7a986a98c59f0f32f0c (patch)
treef0fe7c39fb19d0b29d28fb1e91fa4b344bbf2acb /core/java/android/webkit/WebViewFragment.java
parent54fa6196b0058933a68cffde17b4413b098630d3 (diff)
Fix WebViewFragment to avoid detroying the WebView too early
We must not call WebView.destroy() until after the WebView has been removed from the view hierarchy. Bug: 4974517 Change-Id: I33b3a9d4ec098e2ab50626cb8906da7697ff2a33
Diffstat (limited to 'core/java/android/webkit/WebViewFragment.java')
-rw-r--r--core/java/android/webkit/WebViewFragment.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/core/java/android/webkit/WebViewFragment.java b/core/java/android/webkit/WebViewFragment.java
index 466f1740b190..852878b278ca 100644
--- a/core/java/android/webkit/WebViewFragment.java
+++ b/core/java/android/webkit/WebViewFragment.java
@@ -30,6 +30,7 @@ import android.webkit.WebView;
*/
public class WebViewFragment extends Fragment {
private WebView mWebView;
+ private boolean mIsWebViewAvailable;
public WebViewFragment() {
}
@@ -40,7 +41,11 @@ public class WebViewFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ if (mWebView != null) {
+ mWebView.destroy();
+ }
mWebView = new WebView(getActivity());
+ mIsWebViewAvailable = true;
return mWebView;
}
@@ -63,19 +68,31 @@ public class WebViewFragment extends Fragment {
}
/**
- * Called when the view has been detached from the fragment. Destroys the WebView.
+ * Called when the WebView has been detached from the fragment.
+ * The WebView is no longer available after this time.
*/
@Override
public void onDestroyView() {
- mWebView.destroy();
- mWebView = null;
+ mIsWebViewAvailable = false;
super.onDestroyView();
}
/**
+ * Called when the fragment is no longer in use. Destroys the internal state of the WebView.
+ */
+ @Override
+ public void onDestroy() {
+ if (mWebView != null) {
+ mWebView.destroy();
+ mWebView = null;
+ }
+ super.onDestroy();
+ }
+
+ /**
* Gets the WebView.
*/
public WebView getWebView() {
- return mWebView;
+ return mIsWebViewAvailable ? mWebView : null;
}
}