SlideShare a Scribd company logo
1 of 11
ANDROIDTASK AND BACK
STACK REVIEW
http://www.asterixsolution.com/android-development-course.html
• ATask holds the Activities, arranged in a Stack called Back Stack.The Stack has LIFO
structure and stores the activities in the order of their opening.The Activities in the
Stack are never rearranged.The navigation of the back stack is done with the help of
the Back button.
We will now go through the default behavior of theTask and the Back Stack.
• The application launcher creates a newTask with the main Activity created and
placed in the root of the back stack (It has another role that we will review later).
• When the current Activity starts another Activity, then the new Activity is pushed on
top of the stack and takes focus.
• Android Activities are the logical construct of the screens that we want a user to
navigate through.The relation that each Activity holds with respect to other is very
crucial for a good user experience. This relation should be designed with the focus of
developing an effortless and pattern forming strategy from the user’s perspective.
• One of the most important aspects of achieving the above is to design a proper
forward and backward navigations.The Android design already has taken a very good
care of providing a smooth user experience in terms of managing the screen flows.
• The previous Activity moves below this new Activity in the back stack and is stopped.
The system retains the current state of this Activity’s user interfaces like text in the
form, scroll position etc.
• The subsequent new Activities keep on piling the back stack.
• When the Back button is pressed then the current Activity is popped from the top of
the back stack.This destroys the Activity and the previous Activity resumes with its
state restored.
• When the back stack goes empty then theTask ceased to exist.
• The Back button then keeps on popping the current Activities and restoring the
previous activities.When the last Activity is removed from the back stack, then the
Task terminates to the screen that was last running before the creation of theTask (in
our case the launcher screen).
• Activities of different applications invoked by the intent are put into the sameTask.
Task has few important properties:
• It goes into the background when a new task is created or when the Home button is
pressed.
• It is then brought to the foreground by clicking the launcher icon (this is the another
role of the launcher icon that we mentioned earlier) or by selecting the task from the
recent screens.
• When multiple tasks are in the background or when the user leaves theTask for a long time, the
system in order to recover memory clears theTask of all the Activities except the root Activity.
When the user returns to theTask again, only the root Activity is restored (this behavior can be
overridden as we will see later).
An Important Result:
• We can derive from the above text a very important result. If an Activity is started from multiple
Activities, then a new instance of that Activity is created and pushed on the stack rather than
bringing the previous instance of that Activity to the top. In this case, the Back button reveals the
instance of the same Activity multiple times with its state in the order is was created.
• There are few situations where we would want the manage theTask as a deviation from the
default behavior.The Android Developer Guide lists some of those situations as follows:
• When starting a new Activity, it is required to start in a newTask rather than being placed in the
back stack of the existingTask.
• When starting a new Activity the existing instance is required to be brought from the back stack
as we already mentioned.
• The back stack should be cleared to the root Activity when a user leaves the existing Activity.
• Using Android Manifest <activity>
• The launch Modes and its equivalent start Activity Flags allow us to define, how a new instance of
an Activity is associated with the currentTask and specifies the instruction for its launch in the
givenTask.
• The types of launch Modes and its equivalent start Activity Flags are presented and investigated
in the following points (not all launch Modes have its start Activity flag counterpart and vice versa):
• launchMode — standard:This is the default mode of the Activity. In this mode, a
new instance of the Activity is created and put in theTask which started it by
routing the intent to it.The Activity in this mode can be instantiated multiple
times, each instance can belong to a different task and one task can have its
multiple instances.
• launchMode — singleTop | flag — FLAG_ACTIVITY_SINGLE_TOP: This mode or
flag produces exactly the same behavior as the standard launchMode if the new
Activity in not already present in the back stack as the top. If it is present at the
top then it behaves differently. In this case, the same Activity resumes with the call
to its onNewIntent method.
• launchMode — singleInstance:This launchMode is similar to the singleTask
except that the System doesn’t launch any other Activity into theTask holding the
instance.The Activity is always the single and the only member of itsTask. Any
Activity started by this one opens in a separateTask.
• flag — FLAG_ACTIVITY_CLEAR_TASK: This clears any existing task that would
be associated with the Activity before the Activity is started.This Activity then
becomes the new root of the task and old Activities are finished. It can only be
used in conjunction with FLAG_ACTIVITY_NEW_TASK.
• This particular flag is useful when the notification has to start the application by
finishing the existing Activities. For example, if we want to start the SplashActivity
from the Notification callback handler Service
• Note: For FLAG_ACTIVITY_CLEAR_TOP, if the launchMode is not defined in the
AndroidManifest or set as “standard” for the Activity then the Activity along with its top is
popped and a new instance of that Activity is placed on the top. So, onNewIntent method is not
called.
• This is undesirable, most of the time we would want to reuse the Activity and refresh it’s view
states like, the data in the list, when it comes to the top of the back stack, rather than
destroying and then recreating it.
• Let’s explore few of the important Activity’s manifest attributes related to the back stack.
• noHistory: If this is set to true then it destroys the current Activity and removes it from the
back stack whenever any other Activity is started by it.You don’t have to explicitly call finish for
this activity. It is effective in SplashActivity.
• clearTaskOnLaunch: If this is set to true then the back stack is cleared down to the root
Activity whenever the user leaves theTask and return to it.
• finishOnTaskLaunch: It is similar to clearTaskOnLaunch but operates on a single Activity.
www.facebook.com/asterixsolutionlab
www.plus.google.com/+Asterixsolutionlab
www.asterixsolution.com

More Related Content

Similar to Android Developer Training

Android activity
Android activityAndroid activity
Android activityMohNage7
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxShantanuDharekar
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intentDiego Grancini
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaJAX London
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 ThreadingDiego Grancini
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116PrathishGM
 
How can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state pptHow can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state pptBOSC Tech Labs
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 

Similar to Android Developer Training (20)

Android activity
Android activityAndroid activity
Android activity
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
 
Fragment
Fragment Fragment
Fragment
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
android activity
android activityandroid activity
android activity
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Lab3-Android
Lab3-AndroidLab3-Android
Lab3-Android
 
Android activity
Android activityAndroid activity
Android activity
 
Android activity
Android activityAndroid activity
Android activity
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
How can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state pptHow can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state ppt
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 

More from faizrashid1995

Android Developer Training
Android Developer TrainingAndroid Developer Training
Android Developer Trainingfaizrashid1995
 
Big data and apache hadoop adoption
Big data and apache hadoop adoptionBig data and apache hadoop adoption
Big data and apache hadoop adoptionfaizrashid1995
 
Big Data Courses In Mumbai
Big Data Courses In MumbaiBig Data Courses In Mumbai
Big Data Courses In Mumbaifaizrashid1995
 
Python Classes In Thane
Python Classes In ThanePython Classes In Thane
Python Classes In Thanefaizrashid1995
 
python classes in thane
python classes in thanepython classes in thane
python classes in thanefaizrashid1995
 
Hadoop training in mumbai
Hadoop training in mumbaiHadoop training in mumbai
Hadoop training in mumbaifaizrashid1995
 
android development training in mumbai
android development training in mumbaiandroid development training in mumbai
android development training in mumbaifaizrashid1995
 

More from faizrashid1995 (12)

Hadoop Training
Hadoop TrainingHadoop Training
Hadoop Training
 
Android Developer Training
Android Developer TrainingAndroid Developer Training
Android Developer Training
 
Big data and apache hadoop adoption
Big data and apache hadoop adoptionBig data and apache hadoop adoption
Big data and apache hadoop adoption
 
What is hadoop
What is hadoopWhat is hadoop
What is hadoop
 
What is python
What is pythonWhat is python
What is python
 
The mean stack
The mean stackThe mean stack
The mean stack
 
Big Data Courses In Mumbai
Big Data Courses In MumbaiBig Data Courses In Mumbai
Big Data Courses In Mumbai
 
Python Classes In Thane
Python Classes In ThanePython Classes In Thane
Python Classes In Thane
 
python classes in thane
python classes in thanepython classes in thane
python classes in thane
 
Hadoop training in mumbai
Hadoop training in mumbaiHadoop training in mumbai
Hadoop training in mumbai
 
Advanced java course
Advanced java courseAdvanced java course
Advanced java course
 
android development training in mumbai
android development training in mumbaiandroid development training in mumbai
android development training in mumbai
 

Recently uploaded

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
How to Manage Engineering to Order in Odoo 17
How to Manage Engineering to Order in Odoo 17How to Manage Engineering to Order in Odoo 17
How to Manage Engineering to Order in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 

Recently uploaded (20)

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
How to Manage Engineering to Order in Odoo 17
How to Manage Engineering to Order in Odoo 17How to Manage Engineering to Order in Odoo 17
How to Manage Engineering to Order in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 

Android Developer Training

  • 1. ANDROIDTASK AND BACK STACK REVIEW http://www.asterixsolution.com/android-development-course.html
  • 2. • ATask holds the Activities, arranged in a Stack called Back Stack.The Stack has LIFO structure and stores the activities in the order of their opening.The Activities in the Stack are never rearranged.The navigation of the back stack is done with the help of the Back button. We will now go through the default behavior of theTask and the Back Stack. • The application launcher creates a newTask with the main Activity created and placed in the root of the back stack (It has another role that we will review later). • When the current Activity starts another Activity, then the new Activity is pushed on top of the stack and takes focus.
  • 3. • Android Activities are the logical construct of the screens that we want a user to navigate through.The relation that each Activity holds with respect to other is very crucial for a good user experience. This relation should be designed with the focus of developing an effortless and pattern forming strategy from the user’s perspective. • One of the most important aspects of achieving the above is to design a proper forward and backward navigations.The Android design already has taken a very good care of providing a smooth user experience in terms of managing the screen flows.
  • 4. • The previous Activity moves below this new Activity in the back stack and is stopped. The system retains the current state of this Activity’s user interfaces like text in the form, scroll position etc. • The subsequent new Activities keep on piling the back stack. • When the Back button is pressed then the current Activity is popped from the top of the back stack.This destroys the Activity and the previous Activity resumes with its state restored. • When the back stack goes empty then theTask ceased to exist.
  • 5. • The Back button then keeps on popping the current Activities and restoring the previous activities.When the last Activity is removed from the back stack, then the Task terminates to the screen that was last running before the creation of theTask (in our case the launcher screen). • Activities of different applications invoked by the intent are put into the sameTask. Task has few important properties: • It goes into the background when a new task is created or when the Home button is pressed. • It is then brought to the foreground by clicking the launcher icon (this is the another role of the launcher icon that we mentioned earlier) or by selecting the task from the recent screens.
  • 6. • When multiple tasks are in the background or when the user leaves theTask for a long time, the system in order to recover memory clears theTask of all the Activities except the root Activity. When the user returns to theTask again, only the root Activity is restored (this behavior can be overridden as we will see later). An Important Result: • We can derive from the above text a very important result. If an Activity is started from multiple Activities, then a new instance of that Activity is created and pushed on the stack rather than bringing the previous instance of that Activity to the top. In this case, the Back button reveals the instance of the same Activity multiple times with its state in the order is was created. • There are few situations where we would want the manage theTask as a deviation from the default behavior.The Android Developer Guide lists some of those situations as follows:
  • 7. • When starting a new Activity, it is required to start in a newTask rather than being placed in the back stack of the existingTask. • When starting a new Activity the existing instance is required to be brought from the back stack as we already mentioned. • The back stack should be cleared to the root Activity when a user leaves the existing Activity. • Using Android Manifest <activity> • The launch Modes and its equivalent start Activity Flags allow us to define, how a new instance of an Activity is associated with the currentTask and specifies the instruction for its launch in the givenTask. • The types of launch Modes and its equivalent start Activity Flags are presented and investigated in the following points (not all launch Modes have its start Activity flag counterpart and vice versa):
  • 8. • launchMode — standard:This is the default mode of the Activity. In this mode, a new instance of the Activity is created and put in theTask which started it by routing the intent to it.The Activity in this mode can be instantiated multiple times, each instance can belong to a different task and one task can have its multiple instances. • launchMode — singleTop | flag — FLAG_ACTIVITY_SINGLE_TOP: This mode or flag produces exactly the same behavior as the standard launchMode if the new Activity in not already present in the back stack as the top. If it is present at the top then it behaves differently. In this case, the same Activity resumes with the call to its onNewIntent method.
  • 9. • launchMode — singleInstance:This launchMode is similar to the singleTask except that the System doesn’t launch any other Activity into theTask holding the instance.The Activity is always the single and the only member of itsTask. Any Activity started by this one opens in a separateTask. • flag — FLAG_ACTIVITY_CLEAR_TASK: This clears any existing task that would be associated with the Activity before the Activity is started.This Activity then becomes the new root of the task and old Activities are finished. It can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK. • This particular flag is useful when the notification has to start the application by finishing the existing Activities. For example, if we want to start the SplashActivity from the Notification callback handler Service
  • 10. • Note: For FLAG_ACTIVITY_CLEAR_TOP, if the launchMode is not defined in the AndroidManifest or set as “standard” for the Activity then the Activity along with its top is popped and a new instance of that Activity is placed on the top. So, onNewIntent method is not called. • This is undesirable, most of the time we would want to reuse the Activity and refresh it’s view states like, the data in the list, when it comes to the top of the back stack, rather than destroying and then recreating it. • Let’s explore few of the important Activity’s manifest attributes related to the back stack. • noHistory: If this is set to true then it destroys the current Activity and removes it from the back stack whenever any other Activity is started by it.You don’t have to explicitly call finish for this activity. It is effective in SplashActivity. • clearTaskOnLaunch: If this is set to true then the back stack is cleared down to the root Activity whenever the user leaves theTask and return to it. • finishOnTaskLaunch: It is similar to clearTaskOnLaunch but operates on a single Activity.