diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index 8f1f1ab2e5c07..275ef574e1d45 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -284,7 +284,12 @@ public final class SelectionActionModeHelper { @Nullable SelectionResult result) { final Layout layout = mTextView.getLayout(); - final Runnable onAnimationEndCallback = () -> startSelectionActionMode(result); + final Runnable onAnimationEndCallback = () -> { + if (result.mStart >= 0 && result.mEnd <= getText(mTextView).length() + && result.mStart <= result.mEnd) { + startSelectionActionMode(result); + } + }; // TODO do not trigger the animation if the change included only non-printable characters final boolean didSelectionChange = result != null && (mTextView.getSelectionStart() != result.mStart