Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android back stack and Memory reclaim

I am learning android app development. I am reading about how activities are managed by the system.

By reading this documentation. Here is the confusion.

  1. I create app A (from home screen) with 3 activities A1, A2, A3 [this is Task A]
  2. I create app B (from home screen) with 3 activities B1, B2, B3 [this is Task B] where A1 and B1 are the top of the stack in app A and B respectively.

As per the documentation system only pushes and pops the activity (No reordering, which makes sense for a stack) But, it states system can reclaim memory in case not enough memory is available. And to pick which activity to remove system always picks the one which is in background. So say its removing activity A3. But A3 is at bottom of the stack. How can it remove A3 without reordering the stack for app A?

I hope I am clear with my question

Thank You,

like image 255
newbee Avatar asked Mar 08 '26 16:03

newbee


1 Answers

The back stack is not changed when an activity is removed from memory.

However, when the user hits the back button and goes back to an activity that has been reclaimed, then any state you do not specifically save in your onSaveInstanceState() (and reload from the savedInstanceBundle argument in onCreate()) will be lost.

like image 133
ianhanniballake Avatar answered Mar 14 '26 02:03

ianhanniballake



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!