Fix #1566 - Migrate remaining onBackPressed() overrides to OnBackPressedCallback#1571
Conversation
…OnBackPressedCallback On Android 13+ (API 33+), back presses route through OnBackPressedDispatcher, whose fallback calls ComponentActivity.super.onBackPressed() directly, silently bypassing subclass overrides of onBackPressed(). Migrate the two remaining affected activities to register an OnBackPressedCallback in onCreate(), mirroring the HomeActivity fix from OneBusAway#1563: - TripPlanActivity: panel-collapse logic now runs on back press again. Also route the toolbar home button through the dispatcher so software and hardware back stay consistent. - InfrastructureIssueActivity: the services spinner reset now runs after each back press again. The callback temporarily disables itself to let the fragment back stack pop (or the activity finish), then re-enables for subsequent presses.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo Android activities migrate from deprecated ChangesBack-press dispatcher migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Fixes #1566
Background
On Android 13+ (API 33+), back presses route through
WindowOnBackInvokedDispatcher→ AndroidXOnBackPressedDispatcher, whose fallback callsComponentActivity.super.onBackPressed()directly — silently bypassing subclass overrides. #1563 fixed this forHomeActivity; this PR migrates the two remaining activities the same way.Changes
TripPlanActivityOnBackPressedCallbackinonCreate()that collapses the sliding itinerary panel when expanded, otherwise disables itself and re-dispatches — mirroring the Fix arrivals onBackPressed() on Android 13+ #1563 pattern.onOptionsItemSelected(toolbar up button) now callsgetOnBackPressedDispatcher().onBackPressed()instead of the deprecatedonBackPressed(), keeping software and hardware back consistent.InfrastructureIssueActivityOnBackPressedCallbackinonCreate()that temporarily disables itself, re-dispatches (so the fragment back stack pops, or the activity finishes), then re-enables itself and resetsmServicesSpinner.HomeActivity/TripPlanActivitypattern: this activity survives repeated back presses while report fragments pop, and the spinner reset must run after each one — matching the originalsuper.onBackPressed(); setSelection(0)semantics.SurveyViewUtils.java(BottomSheetDialog.onBackPressed()) is untouched, as scoped out by the issue. No ActivityonBackPressed()overrides remain in the app.Testing
compileObaGoogleDebugJavaWithJavac).Summary by CodeRabbit