- // Update the action mode subtitle according to the number of selected bookmarks.
- mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
-
- // Update the visibility of the the select all menu.
- if (bookmarksListView.getCheckedItemCount() == bookmarksListView.getCount()) { // All of the bookmarks are checked.
- // Hide the select all menu item.
- selectAllMenuItem.setVisible(false);
- } else { // Not all of the bookmarks are checked.
- // Show the select all menu item.
- selectAllMenuItem.setVisible(true);
- }
+ // Only run the commands if at least one bookmark is selected. Otherwise, a context menu with 0 selected bookmarks is briefly displayed.
+ if (numberOfSelectedBookmarks > 0) {
+ // Update the action mode subtitle according to the number of selected bookmarks.
+ mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
+
+ // Update the visibility of the the select all menu.
+ if (bookmarksListView.getCheckedItemCount() == bookmarksListView.getCount()) { // All of the bookmarks are checked.
+ // Hide the select all menu item.
+ selectAllMenuItem.setVisible(false);
+ } else { // Not all of the bookmarks are checked.
+ // Show the select all menu item.
+ selectAllMenuItem.setVisible(true);
+ }