Skip to content

Conversation

@ycheng-kickstarter
Copy link
Contributor

@ycheng-kickstarter ycheng-kickstarter commented Aug 19, 2025

📲 What

Properly intercept back navigation, which involves replacing back interceptions from KeyEvent.KEYCODE_BACK and any classes with onBackPressed methods such as Activity and Dialog with the new system Back APIs.

🤔 Why

Support predictive back for Android 16: https://developer.android.com/about/versions/16/behavior-changes-16#predictive-back

🛠 How

Most of our app was already using the backward compatible OnBackPressedCallback API. All I did was remove a couple of places where we were calling the deprecated onBackPressed().

👀 See

Note! You'll need to set compilesdk and targetsdk = 36 in build.gradle(app) because predictive back animation is set by default in Android 16.

Compare back-to-home animations of Chrome (opted-in), Kickstarter (opted-in), and Slack (not targeting api 36 yet so not opted-in)

Screen_recording_20250819_111022.mp4

📋 QA

Set compilesdk and targetsdk = 36 in build.gradle(app).
Open the app, and swipe back to view the back-to-home animation.

Story 📖

https://kickstarter.atlassian.net/browse/MBL-2704

} else {
(context as AppCompatActivity).onBackPressed()
}
(context as ComponentActivity).onBackPressedDispatcher.onBackPressed()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AppCompatActivity extends ComponentActivity so there is no need to call the deprecated onBackPressed on an AppCompatActivity.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.21%. Comparing base (71e6e9c) to head (da21364).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2407      +/-   ##
============================================
- Coverage     66.21%   66.21%   -0.01%     
+ Complexity     2353     2352       -1     
============================================
  Files           378      378              
  Lines         28043    28043              
  Branches       4255     4255              
============================================
- Hits          18569    18568       -1     
  Misses         7204     7204              
- Partials       2270     2271       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ycheng-kickstarter ycheng-kickstarter marked this pull request as ready for review August 19, 2025 16:57
@ycheng-kickstarter ycheng-kickstarter merged commit 875358b into master Aug 20, 2025
3 checks passed
@ycheng-kickstarter ycheng-kickstarter deleted the MBL-2704-predictive-back branch August 20, 2025 15:36
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.

4 participants