How To Migrate The Deprecated OnBackPressed Function

Get ready for Android 13’s predictive back gesture

Yanneck Reiß
Tech Takeaways

--

Original photo by Tim Douglas from Pexels

Starting with Android 13 (API Level 33), the onBackPressed() function has been marked as deprecated.

If you visit the official documentation of onBackPressed(), you will see the note “Starting from Android 13 (API level 33), back event handling is moving to an ahead-of-time model and Activity#onBackPressed() and KeyEvent#KEYCODE_BACK should not be used to handle back events (back gesture or back button click)”.

But why is that and what does that mean for our Android apps and how can we replace the deprecated parts? These questions will be answered in this article.

This article is also available as a YouTube video

Predictive Back Gesture

The predictive back gesture is a part of Android 13. However, at the time of writing, Android 13 has already been released, but the predictive back gesture is still in preview and will be taking part in a

--

--

Yanneck Reiß
Tech Takeaways

Follow me on my journey as a professional mobile and fullstack developer