سؤال

I am trying to Understand what is a back stack concept in Android

What i have tried to learn: I went through the Developer site

  • what i could learn is that, back stack is the one concept that differs fragment lifecycle from regular activity life cycle
  • When the activity is placed to back-stack of activities, the user can navigate back to previous activity by just pressing the back button

My question::

  • Does this mean i can add activity1- - activity2- -activity3 .... then activity3 is at top of the back stack so if i press back button .... I go from activity3 - - to - - activity2 ...... then again i go from activity2 - - activity1 finally
  • What more can i add for my learning ?

[EDIT]

  • Also i remember using finish() to navigate back in regular activity life cycle
  • Does this mean that regular activity life cycle also has back stack ..... if no ?
  • How different is back stack from using a finish() in regular activity life cycle
هل كانت مفيدة؟

المحلول

You can read this detailed Documentation (Developer Site) and this Presentation
Along with that there are many other things that you can do with Back Stack, for example:

  1. How to find back stack activities in an android application?
  2. How to Control Android back stack

I hope this helps.

EDIT:

Activity Life Cycle and Back Stack are 2 different entities.

When Activity's finish() is called, the Activity is Stopped() and removed from the Back Stack.
The Back Stack is updated in conjunction with the Activity's Life Cycle.
Like when a new Activity is started, the Back Stack is updated and the current Activity is stacked at the Top and when an Activity is finished, the Back Stack is updated again and the former Activity is removed from it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top