Skip to content

Commit 88b6fe0

Browse files
committed
Prevent webview from going back to the loading page.
1 parent a5a89e9 commit 88b6fe0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,17 @@ public void onClick(DialogInterface dialog,int id) {
156156

157157
// Set up the webview
158158
String app_root_dir = getAppRoot();
159+
final String load_url = "file:///android_asset/_load.html";
159160

160161
mWebView = new WebView(PythonActivity.mActivity);
161162
mWebView.getSettings().setJavaScriptEnabled(true);
162163
mWebView.getSettings().setDomStorageEnabled(true);
163-
mWebView.loadUrl("file:///android_asset/_load.html");
164+
mWebView.loadUrl(load_url);
164165

165166
mWebView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
166167
mWebView.setWebViewClient(new WebViewClient() {
168+
boolean first_load_complete = false;
169+
167170
@Override
168171
public boolean shouldOverrideUrlLoading(WebView view, String url) {
169172
Uri u = Uri.parse(url);
@@ -180,6 +183,12 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
180183
@Override
181184
public void onPageFinished(WebView view, String url) {
182185
CookieManager.getInstance().flush();
186+
// Make sure that any attempts to use back functionality don't take us back to the loading screen
187+
// For more info, see: https://stackoverflow.com/questions/8103532/how-to-clear-webview-history-in-android
188+
if (!first_load_complete && !url.equals(load_url)) {
189+
first_load_complete = true;
190+
mWebView.clearHistory();
191+
}
183192
}
184193
});
185194
mLayout = new AbsoluteLayout(PythonActivity.mActivity);

0 commit comments

Comments
 (0)