From 672a85bcf4285ea54d1479b5f6182f63bea84ab2 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 13 Mar 2015 21:12:21 +0100 Subject: [PATCH] Fix crashes when selecting messages in the message list Throughout the code we make the assumption that onPrepareActionMode() is called right after starting the action mode. However, this is not the case on Android 5.1. With this change we call ActionMode.invalidate() right after starting the action mode which causes onPrepareActionMode() to be invoked. --- src/com/fsck/k9/fragment/MessageListFragment.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/com/fsck/k9/fragment/MessageListFragment.java b/src/com/fsck/k9/fragment/MessageListFragment.java index f6bd09f74..205383e55 100644 --- a/src/com/fsck/k9/fragment/MessageListFragment.java +++ b/src/com/fsck/k9/fragment/MessageListFragment.java @@ -2224,7 +2224,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener } if (mActionMode == null) { - mActionMode = getActivity().startActionMode(mActionModeCallback); + startAndPrepareActionMode(); } computeBatchDirection(); updateActionModeTitle(); @@ -2283,7 +2283,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener return; } } else { - mActionMode = getActivity().startActionMode(mActionModeCallback); + startAndPrepareActionMode(); } if (selected) { @@ -3542,13 +3542,18 @@ public class MessageListFragment extends Fragment implements OnItemClickListener } if (mActionMode == null) { - mActionMode = getActivity().startActionMode(mActionModeCallback); + startAndPrepareActionMode(); } recalculateSelectionCount(); updateActionModeTitle(); } + private void startAndPrepareActionMode() { + mActionMode = getActivity().startActionMode(mActionModeCallback); + mActionMode.invalidate(); + } + /** * Recalculates the selection count. *