Managing Launcher Shortcuts

Android Nougat

I recently found myself needing to complete a German writing task, respond to a few emails and revise for a geography test. Obviously I decided to procratinate by adding a small feature to my Android App - Monitor for EnergyHive & Engage.

Launcher shortcuts seemed pretty simple at first. All I had to do was create the shortcut info with the intent, icon and label and then add it using ShortcutManager.

It worked great until I hit the limit at which instead of silently handling the exception, the app decides to crash.

Okay, so I need to keep the number of shortcuts below 5 (inclusive). This code should work, right?

List<ShortcutInfo> oldShortcuts = shortcutManager.getDynamicShortcuts();
List<ShortcutInfo> newShortcuts = new ArrayList<>();
for (int i = 0; i < (oldShortcuts.size() < 5 ? oldShortcuts.size() : 5); i++) {

Nope. For some reason the icons are lost in the process.


I found the best way of managing them for now is like so:

ArrayList<ShortcutInfo> dynamicShortcuts = new ArrayList<>();

boolean alreadyAdded = false;
for (ShortcutInfo s :
        dynamicShortcuts) {
    if (s.getId().equals(shortcut.getId())) {
        alreadyAdded = true;

if (!alreadyAdded && dynamicShortcuts.size() > 3) {


Let me know if you have a solution…