Browse Source

Correctly remove WebView from layout before destroying it. throw exception if destroy is called without remove

master
Anthony Restaino 9 years ago
parent
commit
46b1269730
  1. 7
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 3
      app/src/main/java/acr/browser/lightning/view/LightningView.java

7
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -1045,6 +1045,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
closeActivity(); closeActivity();
return; return;
} else { } else {
if (tabToDelete.getWebView() != null) {
mBrowserFrame.removeView(tabToDelete.getWebView());
}
mTabsManager.deleteTab(position); mTabsManager.deleteTab(position);
} }
final LightningView afterTab = mTabsManager.getCurrentTab(); final LightningView afterTab = mTabsManager.getCurrentTab();
@ -1102,6 +1105,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
void closeBrowser() { void closeBrowser() {
mBrowserFrame.setBackgroundColor(mBackgroundColor); mBrowserFrame.setBackgroundColor(mBackgroundColor);
performExitCleanUp(); performExitCleanUp();
LightningView currentTab = mTabsManager.getCurrentTab();
if (currentTab != null && currentTab.getWebView() != null) {
mBrowserFrame.removeView(currentTab.getWebView());
}
mTabsManager.shutdown(); mTabsManager.shutdown();
mEventBus.post(new BrowserEvents.TabsChanged()); mEventBus.post(new BrowserEvents.TabsChanged());
finish(); finish();

3
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -772,8 +772,7 @@ public class LightningView {
// before calling destroy() so that a memory leak is not created // before calling destroy() so that a memory leak is not created
ViewGroup parent = (ViewGroup) mWebView.getParent(); ViewGroup parent = (ViewGroup) mWebView.getParent();
if (parent != null) { if (parent != null) {
Log.e(Constants.TAG, "WebView was not detached from window before onDestroy"); throw new RuntimeException("WebView was not detached from window before onDestroy");
parent.removeView(mWebView);
} }
mWebView.stopLoading(); mWebView.stopLoading();
mWebView.onPause(); mWebView.onPause();

Loading…
Cancel
Save