- // Adjust the ActionMode and the menu according to the number of selected bookmarks.
- if (numberOfSelectedBookmarks == 1) { // One bookmark is selected.
- // List the number of selected bookmarks in the subtitle.
- mode.setSubtitle(getString(R.string.selected) + " 1");
-
- // Show the `Move Up`, `Move Down`, and `Edit` options.
- moveBookmarkUpMenuItem.setVisible(true);
- moveBookmarkDownMenuItem.setVisible(true);
- editBookmarkMenuItem.setVisible(true);
-
- // Update the enabled status of the move icons.
- updateMoveIcons();
- } else { // More than one bookmark is selected.
- // List the number of selected bookmarks in the subtitle.
- mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
-
- // Hide non-applicable `MenuItems`.
- moveBookmarkUpMenuItem.setVisible(false);
- moveBookmarkDownMenuItem.setVisible(false);
- editBookmarkMenuItem.setVisible(false);
- }
+ // Only process commands if at least one bookmark is selected. Otherwise, a context menu with 0 selected bookmarks is briefly displayed.
+ if (numberOfSelectedBookmarks > 0) {
+ // Adjust the ActionMode and the menu according to the number of selected bookmarks.
+ if (numberOfSelectedBookmarks == 1) { // One bookmark is selected.
+ // List the number of selected bookmarks in the subtitle.
+ mode.setSubtitle(getString(R.string.selected) + " 1");
+
+ // Show the `Move Up`, `Move Down`, and `Edit` options.
+ moveBookmarkUpMenuItem.setVisible(true);
+ moveBookmarkDownMenuItem.setVisible(true);
+ editBookmarkMenuItem.setVisible(true);
+
+ // Update the enabled status of the move icons.
+ updateMoveIcons();
+ } else { // More than one bookmark is selected.
+ // List the number of selected bookmarks in the subtitle.
+ mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
+
+ // Hide non-applicable `MenuItems`.
+ moveBookmarkUpMenuItem.setVisible(false);
+ moveBookmarkDownMenuItem.setVisible(false);
+ editBookmarkMenuItem.setVisible(false);
+ }