Skip to content

Commit

Permalink
Merge pull request #10 from SilenceDut/master
Browse files Browse the repository at this point in the history
fix Memory Leak cause by Webview
  • Loading branch information
TheFinestArtist committed Dec 26, 2015
2 parents daa91e5 + 7a72329 commit ebf0136
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
Expand Down Expand Up @@ -281,6 +282,7 @@ protected void getOptions() {
protected TextView menuCopyLinkTv;
protected LinearLayout menuOpenWith;
protected TextView menuOpenWithTv;
protected FrameLayout webLayout;

protected void bindViews() {
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
Expand All @@ -298,7 +300,7 @@ protected void bindViews() {
more = (ImageButton) findViewById(R.id.more);

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
webView = (WebView) findViewById(R.id.webView);


gradient = findViewById(R.id.gradient);
divider = findViewById(R.id.divider);
Expand All @@ -316,6 +318,9 @@ protected void bindViews() {
menuCopyLinkTv = (TextView) findViewById(R.id.menuCopyLinkTv);
menuOpenWith = (LinearLayout) findViewById(R.id.menuOpenWith);
menuOpenWithTv = (TextView) findViewById(R.id.menuOpenWithTv);
webLayout=(FrameLayout)findViewById(R.id.webLayout);
webView = new WebView(getApplicationContext());
webLayout.addView(webView);
}

protected void layoutViews() {
Expand Down Expand Up @@ -882,7 +887,9 @@ public void onConfigurationChanged(Configuration newConfig) {
@Override
protected void onDestroy() {
super.onDestroy();
if (webView != null)
if(webLayout!=null) {
webLayout.removeAllViews();
webView.destroy();
}
}
}
}
11 changes: 5 additions & 6 deletions library/src/main/res/layout/finest_web_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/webLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Expand Down Expand Up @@ -66,4 +65,4 @@

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

</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.CoordinatorLayout>

0 comments on commit ebf0136

Please sign in to comment.