From 921665167f50f85683cdd7154e62fc48841687c1 Mon Sep 17 00:00:00 2001 From: ydinath Date: Mon, 23 Apr 2018 20:23:39 -0400 Subject: [PATCH] canGoBack doesn't work consistently when using loadDataWithBaseURL. Update old logic to allow depth > 1. https://stackoverflow.com/questions/2686933/android-webview-can-render-html-going-forward-but-not-backward https://stackoverflow.com/questions/14948652/webview-cangoback-not-working-when-using-loaddatawithbaseurl/15074071#15074071 --- .../de/danoeh/antennapod/activity/AboutActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index fed22d896..443f4257f 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -36,6 +36,7 @@ public class AboutActivity extends AppCompatActivity { private WebView webView; private LinearLayout webViewContainer; private Subscription subscription; + private int depth = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,6 +57,7 @@ public class AboutActivity extends AppCompatActivity { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + depth++; if (!url.startsWith("http")) { url = url.replace("file:///android_asset/", ""); loadAsset(url); @@ -100,6 +102,10 @@ public class AboutActivity extends AppCompatActivity { "

" + webViewData + "

"; webViewData = webViewData.replace("\n", "
"); } + else + { + depth = 0; + } webViewData = String.format(webViewData, colorString); subscriber.onSuccess(webViewData); } catch (IOException e) { @@ -120,8 +126,9 @@ public class AboutActivity extends AppCompatActivity { @Override public void onBackPressed() { - if (webView.canGoBack()) { + if (depth != 0) { webView.goBack(); + depth--; } else { super.onBackPressed(); }