Skip to content

Commit a5a89e9

Browse files
micahscopesrtibbles
authored andcommitted
comments for back-button fix
1 parent 98d1649 commit a5a89e9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ public static ViewGroup getLayout() {
272272
long lastBackClick = SystemClock.elapsedRealtime();
273273
@Override
274274
public boolean onKeyDown(int keyCode, KeyEvent event) {
275-
// Check if the key event was the Back button and if there's history
275+
// Check if the key event was the Back button
276276
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
277+
// If there's some web history, go back
277278
if(mWebView.canGoBack()) {
278279
mWebView.goBack();
279280
return true;
280281
}
282+
// Otherwise, if it's been a little while since the Back key was
283+
// last pressed, register that it's been pressed and notify the
284+
// user that pressing it again will close the app.
281285
if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
282286
lastBackClick = SystemClock.elapsedRealtime();
283287
Toast.makeText(this, "Click again to close the app",
@@ -286,8 +290,9 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
286290
}
287291
}
288292

289-
// If it wasn't the Back key or there's no web page history, bubble up to the default
290-
// system behavior (probably exit the activity)
293+
// If it wasn't the Back key, or if the user tapped the Back key twice,
294+
// quickly and without web history, bubble up to the default system
295+
// behavior (probably exit the activity)
291296
return super.onKeyDown(keyCode, event);
292297
}
293298

0 commit comments

Comments
 (0)