'android 12 onBackPressed

Android 12 has changed behavior for back button. However, sometimes the behavior is confusing. For example, when I press it, my app does not go away (onResume is called right after onPause); other times, when I press it, my app goes away but a previously used app is opened. Other times, when I press it, my app goes away as expected (as with older versions of Android).

I've seen this behavior with other apps too. For example: the default "Files" app in Google Pixel 3a.

Is it a bug? or can I do something in my app to have always the expected behavior (as with older versions of Android)? Thanks a lot for your time.



Solution 1:[1]

Overriding onBackPressed in your launcher activity and calling finish in it would ensure your app always behaves as with older versions of Android.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arno den Hond