Skip to content

Commit ebf0136

Browse files
Merge pull request #10 from SilenceDut/master
fix Memory Leak cause by Webview
2 parents daa91e5 + 7a72329 commit ebf0136

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.webkit.WebChromeClient;
3131
import android.webkit.WebView;
3232
import android.webkit.WebViewClient;
33+
import android.widget.FrameLayout;
3334
import android.widget.ImageButton;
3435
import android.widget.LinearLayout;
3536
import android.widget.ProgressBar;
@@ -281,6 +282,7 @@ protected void getOptions() {
281282
protected TextView menuCopyLinkTv;
282283
protected LinearLayout menuOpenWith;
283284
protected TextView menuOpenWithTv;
285+
protected FrameLayout webLayout;
284286

285287
protected void bindViews() {
286288
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
@@ -298,7 +300,7 @@ protected void bindViews() {
298300
more = (ImageButton) findViewById(R.id.more);
299301

300302
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
301-
webView = (WebView) findViewById(R.id.webView);
303+
302304

303305
gradient = findViewById(R.id.gradient);
304306
divider = findViewById(R.id.divider);
@@ -316,6 +318,9 @@ protected void bindViews() {
316318
menuCopyLinkTv = (TextView) findViewById(R.id.menuCopyLinkTv);
317319
menuOpenWith = (LinearLayout) findViewById(R.id.menuOpenWith);
318320
menuOpenWithTv = (TextView) findViewById(R.id.menuOpenWithTv);
321+
webLayout=(FrameLayout)findViewById(R.id.webLayout);
322+
webView = new WebView(getApplicationContext());
323+
webLayout.addView(webView);
319324
}
320325

321326
protected void layoutViews() {
@@ -882,7 +887,9 @@ public void onConfigurationChanged(Configuration newConfig) {
882887
@Override
883888
protected void onDestroy() {
884889
super.onDestroy();
885-
if (webView != null)
890+
if(webLayout!=null) {
891+
webLayout.removeAllViews();
886892
webView.destroy();
893+
}
887894
}
888-
}
895+
}

library/src/main/res/layout/finest_web_view.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
<android.support.v4.widget.NestedScrollView
1818
android:layout_width="match_parent"
1919
android:layout_height="match_parent">
20-
21-
<WebView
22-
android:id="@+id/webView"
23-
android:layout_width="match_parent"
24-
android:layout_height="match_parent" />
20+
<FrameLayout
21+
android:id="@+id/webLayout"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"/>
2524

2625
</android.support.v4.widget.NestedScrollView>
2726
</android.support.v4.widget.SwipeRefreshLayout>
@@ -66,4 +65,4 @@
6665

6766
<include layout="@layout/menus" />
6867

69-
</android.support.design.widget.CoordinatorLayout>
68+
</android.support.design.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)