0

I am still fairly new to understanding android and heard about activity stacks.

From what I read and understood was that it creates stack as you progress to each activity and leaves it behind as a stack item.

My question are:

  • Would removing an activity stack cause android to save more memory? eg. such as activity that has a lot of images.

  • Would it be better to remove activity stacks knowing that you want them to start from scratch in the first place?.

If there is anything that has to be corrected on my second sentence please mention it as well.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
Juju
  • 70
  • 8

1 Answers1

2

Would it be better to remove activity stacks knowing that you want them to start from scratch in the first place?.

The activity stack back stack is important because it allows a means of back navigation from screen to screen. Without it, there would be no "back button" navigation and the concept of a "task" wouldn't exist. Android is optimized to manage memory for you (see the documentation on the Activity lifecycle). Activities that are placed on the back stack are still managed by the system; so long that you don't do anything stupid, there shouldn't be any problem. :)

Would it be better to remove activity stacks knowing that you want them to start from scratch in the first place?.

I'm not sure I'm understanding this question correctly, but the answer is most likely "no". If you want to start from scratch (i.e. clear the back stack), then you can use the FLAG_ACTIVITY_CLEAR_TOP flag when launching your new Activity.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
  • Another question if you don't mind. Calling finish() returns to the previous activity and thus telling the activity class to be finished and garbage collected. Does that mean that the activity in the stack disappears? – Juju Jun 01 '12 at 18:08
  • Yes. When you call `finish()`, the top activity is popped from the stack and is destroyed. When `onDestroy()` is called, all of the activity's memory resources are released and will eventually be garbage collected by the system. This is what the "back" button does by default (note that some applications override the back button, so this might not always be the case). – Alex Lockwood Jun 01 '12 at 18:13