Skip to content

🐛 - Cap home shortcuts to 4 to prevent Android crash#614

Merged
guytepper merged 1 commit into
mainfrom
guytepper/fix-max-dynamic-shortcuts
May 18, 2026
Merged

🐛 - Cap home shortcuts to 4 to prevent Android crash#614
guytepper merged 1 commit into
mainfrom
guytepper/fix-max-dynamic-shortcuts

Conversation

@guytepper
Copy link
Copy Markdown
Member

Summary

  • Slice favorite routes to a max of 4 before calling Shortcuts.setShortcuts
  • Prevents IllegalArgumentException: Max number of dynamic shortcuts exceeded on Android devices whose getMaxShortcutCountPerActivity() is lower than the number of saved favorites (reported on Samsung SM-A155F running Android 16). iOS also caps quick actions at 4, so the same constant is safe cross-platform.

Test plan

  • Add 5+ favorite routes on Android and verify the app no longer crashes
  • Confirm the first 4 favorites still appear as home-screen shortcuts on Android and iOS

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request limits the number of home screen shortcuts to four to prevent potential crashes on Android devices. Feedback includes a critical fix for a potential ClassCastException on Android caused by passing a boolean value to the subtitle field instead of a string or undefined, and a suggestion to move the MAX_HOME_SHORTCUTS constant to the top level of the file for better maintainability.

.map((route) => ({
type: `favorite-${route.id}`,
title: route.label || fromText(route),
subtitle: !route.label && toText(route),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The expression !route.label && toText(route) evaluates to false when route.label is present. Passing a boolean value to Shortcuts.setShortcuts for a field that expects a string (like subtitle) can cause a ClassCastException on the native Android side when the library attempts to call getString("subtitle"). It is safer to use a ternary operator to ensure the value is either a string or undefined.

Suggested change
subtitle: !route.label && toText(route),
subtitle: !route.label ? toText(route) : undefined,


// Both iOS quick actions and Android dynamic shortcuts cap at ~4-5 per app;
// some Android devices report lower limits and throw if exceeded.
const MAX_HOME_SHORTCUTS = 4
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While defining the constant here works, it's generally better practice to define configuration constants like MAX_HOME_SHORTCUTS at the top level of the file. This improves visibility and maintainability, especially if the value needs to be referenced elsewhere in the future.

@guytepper guytepper merged commit 9f4aafa into main May 18, 2026
5 checks passed
@guytepper guytepper deleted the guytepper/fix-max-dynamic-shortcuts branch May 18, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant