From c3672cd3f7e2bd87d6de9dada499de82b62fae84 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Wed, 5 Nov 2014 15:17:35 -0800 Subject: Cancel or drop key events if activity is stopped. After an activity instance state is saved due to onStop()/onPause(), there is a small window where it can still get key events like the back button since we still allow the ActivityThread to handle pending messages (like memory trim request) before informing the activity manager that we are done. If the activity is stopped, we will now drop non-terminal input events and set the cancel flag on terminal events. Bug: 18151331 Change-Id: I370d7c871530eea4b16fa42428d0248f1a87abb6 --- core/java/android/view/KeyEvent.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core/java/android/view/KeyEvent.java') diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java index 0701b53e4147..243a0fc17e52 100644 --- a/core/java/android/view/KeyEvent.java +++ b/core/java/android/view/KeyEvent.java @@ -2303,6 +2303,16 @@ public class KeyEvent extends InputEvent implements Parcelable { return (mFlags&FLAG_CANCELED) != 0; } + /** + * Set {@link #FLAG_CANCELED} flag for the key event. + * + * @hide + */ + @Override + public final void cancel() { + mFlags |= FLAG_CANCELED; + } + /** * Call this during {@link Callback#onKeyDown} to have the system track * the key through its final up (possibly including a long press). Note -- cgit v1.2.3