Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 624
Bekzad Nasirakhunov Avatar asked Jan 17 '26 23:01

Bekzad Nasirakhunov


1 Answers

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() 
like image 79
Shivrajsinh Sarvaiya Avatar answered Jan 21 '26 01:01

Shivrajsinh Sarvaiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!