Skip to content

Fix #1564 - Launcher shortcuts crash and ignore destination#1565

Merged
aaronbrethorst merged 1 commit into
mainfrom
fix/1564-shortcut-crash
May 28, 2026
Merged

Fix #1564 - Launcher shortcuts crash and ignore destination#1565
aaronbrethorst merged 1 commit into
mainfrom
fix/1564-shortcut-crash

Conversation

@aaronbrethorst

@aaronbrethorst aaronbrethorst commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1564. Two distinct bugs in the launcher-shortcut path, with the same root cause area but different mechanisms:

  • Crash on cold launch. MySearchStopsFragment and MySearchRoutesFragment returned null from onCreateView when the container was null. ViewPager2's FragmentStateAdapter (introduced by the recent Toolbar/edge-to-edge migration in commits d550495a / 999ff8ad) hosts fragments headlessly and always passes a null container, so MySearchFragmentBase.onActivityCreated then crashed at getListView() with IllegalStateException: Content view not yet created. Fixed by inflating against the (possibly-null) container with attachToRoot=false — the canonical fragment idiom that works for both headless and rooted hosts.
  • Wrong destination when the app is already running. UIUtils.makeShortcutInfo was setting only FLAG_ACTIVITY_CLEAR_TOP (from the old Stop shortcuts don't always go directly to ArrivalsListActivity #626 fix), so tapping a shortcut while the app was backgrounded just resumed the app's last screen. Switched to FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK, the documented pattern for launcher shortcuts.

Adds instrumented regression tests for both fixes.

Test plan

  • ./gradlew test connectedObaGoogleDebugAndroidTest — all 223 tests pass.
  • Tap Starred Stops shortcut intent (cold launch): activity opens directly to the Starred tab, no crash.
  • Tap Recent Stops shortcut intent (cold launch): activity opens directly to the Recent tab.
  • Tap Recent Routes shortcut intent (cold launch): activity opens directly to the Recent tab.
  • Tap shortcut intent while the app is backgrounded on HomeActivity: opens the shortcut's destination tab, not HomeActivity.
  • Launch HomeActivity normally: no regression.

Notes for reviewers

  • Existing pinned shortcuts on user devices still carry the old flags. The launcher owns the pinned intent, so this fix only applies to shortcuts pinned after the user installs the new version. Users who already had shortcuts will need to re-pin to benefit from the NEW_TASK | CLEAR_TASK change. The crash fix takes effect immediately for everyone, since the old shortcuts still target the same activity classes.
  • The change to inflate(layout, root, false) (vs. the old inflate(layout, null)) means the inflated view now receives LayoutParams generated from the root when one is present. Both affected layouts (my_search_stop_list.xml, my_search_route_list.xml) already declare fill_parent x fill_parent, and the fragment is always re-parented by the host, so this is equivalent in practice.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Added regression tests verifying search result screens display correctly and launcher shortcuts behave as expected.
  • Bug Fixes

    • Fixed search screens to display correctly when used in different app layout configurations.
    • Fixed launcher shortcuts to properly reset the app task when launched from the home screen.

Review Change Stack

MySearchStopsFragment and MySearchRoutesFragment returned null from
onCreateView when the container was null, but ViewPager2's
FragmentStateAdapter (introduced by the recent Toolbar/edge-to-edge
migration) hosts fragments headlessly and always passes null. The base
class then crashed in onActivityCreated with
"Content view not yet created" when launching MyStopsActivity or
MyRoutesActivity from a pinned launcher shortcut.

Inflate the layout against the container with attachToRoot=false, which
is the canonical fragment pattern and tolerates either null or a real
parent ViewGroup.

Also switch shortcut intents from FLAG_ACTIVITY_CLEAR_TOP to
FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK so tapping a shortcut
while the app is backgrounded opens the shortcut's destination instead
of resuming the app's last screen.

Adds instrumented regression tests for both fixes.
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eb61ff5b-a9d6-4f51-941c-688f93723634

📥 Commits

Reviewing files that changed from the base of the PR and between e65872a and 58afab6.

📒 Files selected for processing (5)
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/MySearchFragmentOnCreateViewTest.java
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/util/test/ShortcutIntentFlagsTest.java
  • onebusaway-android/src/main/java/org/onebusaway/android/ui/MySearchRoutesFragment.java
  • onebusaway-android/src/main/java/org/onebusaway/android/ui/MySearchStopsFragment.java
  • onebusaway-android/src/main/java/org/onebusaway/android/util/UIUtils.java

📝 Walkthrough

Walkthrough

This PR fixes issue #1564 (crash when launched via shortcut) by updating shortcut intent flags to properly create new tasks and by correcting fragment view creation to handle both null and non-null container scenarios.

Changes

Fragment Shortcut Launch Fix

Layer / File(s) Summary
Shortcut intent task flags
onebusaway-android/src/main/java/org/onebusaway/android/util/UIUtils.java, onebusaway-android/src/androidTest/java/org/onebusaway/android/util/test/ShortcutIntentFlagsTest.java
UIUtils.makeShortcutInfo() now sets FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK instead of FLAG_ACTIVITY_CLEAR_TOP, ensuring shortcuts create fresh task stacks. Test verifies the flags are present and the shortcut action is Intent.ACTION_VIEW.
Fragment view creation for container scenarios
onebusaway-android/src/main/java/org/onebusaway/android/ui/MySearchStopsFragment.java, onebusaway-android/src/main/java/org/onebusaway/android/ui/MySearchRoutesFragment.java, onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/MySearchFragmentOnCreateViewTest.java
Both MySearchStopsFragment and MySearchRoutesFragment now unconditionally inflate layouts with their provided root container, removing null-container guard logic. This supports ViewPager2 (null container) and FragmentContainerView (non-null container) hosting. Instrumentation test verifies both fragments return non-null views for both container scenarios via main-thread reflection-based invocation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Fix #1564 - Launcher shortcuts crash and ignore destination' clearly and concisely describes the main changes: fixing crashes when launching via shortcuts and addressing the issue where shortcuts ignore the intended destination.
Linked Issues check ✅ Passed The PR successfully addresses both coding requirements from issue #1564: fixes the crash on cold launch by changing onCreateView to always inflate layouts with containers, and fixes destination handling by updating intent flags to FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #1564: modifying fragment onCreateView methods, updating UIUtils shortcut intent flags, and adding regression tests. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1564-shortcut-crash

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@aaronbrethorst aaronbrethorst merged commit c5dd16d into main May 28, 2026
3 checks passed
@aaronbrethorst aaronbrethorst deleted the fix/1564-shortcut-crash branch May 28, 2026 03:31
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.

Crash when launched via shortcut

1 participant