Pressing back button in Android MainActivity does not destroy the activity anymore. Is it a new feature?

700 Views Asked by At

When I press the back button in MainActivity the home screen is shown, however onDestroy is not being called. Is it a new feature? Using Emulator Pixel 3A in API 33 arm 64-v8a. The same happens through the phone pixel 6A API 33. Also local variables are not deleted.

It should have destroyed MainActivity when the back button is pressed

1

There are 1 best solutions below

0
Shivrajsinh Sarvaiya On

On Android 12+ Devices, back button doesn't result in (main) Activity being destroyed instead app will stay in warm state, similar to when exiting using home button.

Reason behind this change is now user can quickly resume app from a warm state, instead of having to completely restart the app from a cold state.

If you want it function like before then there are two workaround that you can use:

 1. Using AndroidX Activity APIs

 2. By overriding onBackPressed()