Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity is destroyed when new activity is started on Android 8.0

I've noticed a lot of issues with Android 8.0 recently. Right now I've run into an issue specifically for devices running Android 8.0 related to activity lifecycle.

On devices running Android 8.0, when context.startActivity(intent) is called from activity A, activity A is paused, stopped, and destroyed once activity B is launched. When I press back and return to activity A, it needs to be re-instantiated since it was completely destroyed. This is causing issues preserving the state of activity A.

For some reason, this only happens on Android 8.0. On any other OS (have tried 7.1.1 and 9.0), activity A is just paused instead of destroyed, so when I press back from activity B, activity A is just resumed.

Has anyone seem this behavior before? Why would Android 8.0 alone be behaving this way? I haven't seen any documentation related to any changes like this to the lifecycle, and haven't found any other posts about this issue. What could be causing this?

like image 348
Nick Borisenko Avatar asked Nov 26 '25 08:11

Nick Borisenko


1 Answers

The solution to my issue was because of developer settings on the Android device called "Do not keep activities"... if you're ever wondering why activities are randomly dying on your device, make sure that this option is not enabled in your device's developer settings.

like image 117
Nick Borisenko Avatar answered Nov 27 '25 21:11

Nick Borisenko



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!