Destroy webview when it is no longer used

Not destroying the webview might have caused crashes on some devices
This commit is contained in:
daniel oeh 2014-12-08 10:35:02 +01:00
parent bf0257a405
commit 77647cc154
5 changed files with 78 additions and 52 deletions

View File

@ -4,29 +4,43 @@ import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import de.danoeh.antennapod.R;
/** Displays the 'about' screen */
/**
* Displays the 'about' screen
*/
public class AboutActivity extends ActionBarActivity {
private WebView webview;
private WebView webview;
private LinearLayout webviewContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.about);
webview = (WebView) findViewById(R.id.webvAbout);
webview.setWebViewClient(new WebViewClient() {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.about);
webviewContainer = (LinearLayout) findViewById(R.id.webvContainer);
webview = (WebView) findViewById(R.id.webvAbout);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
webview.loadUrl("file:///android_asset/about.html");
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
webview.loadUrl("file:///android_asset/about.html");
}
@Override
protected void onDestroy() {
super.onDestroy();
if (webviewContainer != null && webview != null) {
webviewContainer.removeAllViews();
webview.destroy();
}
}
}

View File

@ -16,6 +16,7 @@ import android.util.Log;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
@ -54,6 +55,7 @@ public class FeedItemDialog extends Dialog {
private FeedItem item;
private QueueAccess queue;
private ViewGroup contentContainer;
private View header;
private TextView txtvTitle;
private WebView webvDescription;
@ -107,6 +109,7 @@ public class FeedItemDialog extends Dialog {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.feeditem_dialog);
contentContainer = (ViewGroup) findViewById(R.id.contentContainer);
txtvTitle = (TextView) findViewById(R.id.txtvTitle);
header = findViewById(R.id.header);
webvDescription = (WebView) findViewById(R.id.webview);
@ -225,6 +228,14 @@ public class FeedItemDialog extends Dialog {
updateMenuAppearance();
}
@Override
public void dismiss() {
super.dismiss();
if (contentContainer != null && webvDescription != null) {
contentContainer.removeAllViews();
webvDescription.destroy();
}
}
private final FeedItemMenuHandler.MenuInterface popupMenuInterface = new FeedItemMenuHandler.MenuInterface() {
@Override

View File

@ -161,11 +161,6 @@ public class ItemDescriptionFragment extends Fragment {
return webvDescription;
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@ -191,6 +186,10 @@ public class ItemDescriptionFragment extends Fragment {
if (webViewLoader != null) {
webViewLoader.cancel(true);
}
if (webvDescription != null) {
webvDescription.removeAllViews();
webvDescription.destroy();
}
}
@SuppressLint("NewApi")

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webvContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

View File

@ -1,58 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtvTitle"
style="@style/AntennaPod.Dialog.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:id="@+id/txtvTitle"
android:layout_alignParentTop="true"
style="@style/AntennaPod.Dialog.Title"
android:maxLines="5"
android:ellipsize="none"/>
android:layout_margin="16dp"
android:ellipsize="none"
android:maxLines="5" />
<View
android:id="@+id/title_divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@id/txtvTitle"
android:background="@color/bright_blue"/>
android:background="@color/bright_blue" />
<LinearLayout
android:id="@+id/header"
android:orientation="horizontal"
android:layout_below="@id/title_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_below="@id/title_divider"
android:orientation="horizontal">
<ImageButton
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:id="@+id/butAction1"
android:background="?attr/selectableItemBackground"
tools:ignore="ContentDescription"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/butAction2"
android:background="?attr/selectableItemBackground"
tools:ignore="ContentDescription"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:id="@+id/butMoreActions"
android:background="?attr/selectableItemBackground"
android:src="?attr/ic_action_overflow"
android:contentDescription="@string/butAction_label"/>
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/butMoreActions"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/butAction_label"
android:src="?attr/ic_action_overflow" />
</LinearLayout>
<View
@ -60,13 +61,13 @@
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@id/header"
android:background="@color/bright_blue"/>
android:background="@color/bright_blue" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/divider"
android:layout_alignParentBottom="true"
android:id="@+id/webview"/>
android:layout_below="@id/divider" />
</RelativeLayout>