SlideShare une entreprise Scribd logo
1  sur  24
Managing Android
                          Back stack
                           Rajdeep Dua
                           June 2012




Monday, March 18, 13
Agenda
               •       Activity Back Stack explained

               •       Tasks

               •       Bringing activities to the foreground

               •       Modifying Activity launch behavior using manifest
                       file attributes

               •       Other advanced behaviors

                       •   No History

                       •   Task Reset

                       •   Task Affinity
Monday, March 18, 13
Android Back Stack


                       •   An Android application is composed of multiple
                           activities
                       •   New Activities are launched using Intents
                       •   Older ones are either destroyed or placed on a
                           back stack




Monday, March 18, 13
Android Back Stack

                       •   New Activity can be launched in the same task or
                           a new task
                       •   Back stack is a data structure which holds activities
                           in the background which user can navigate to using
                           back button.
                       •   Back Stack works in the last in first out mode.
                       •   It can be cleared in case of low memory




Monday, March 18, 13
Tasks

            •          Task is a collection of activities that user performs while
                       doing a job
            •          An activity is launched in a new task from the Home
                       screen
            •          By default all the activities in an application belong to the
                       same task
            •          Activities in a task can exist in the foreground,
                       background as well as on the back stack.



Monday, March 18, 13
Tasks




                       Activity A and Activity B are launched in Task A.
                       By default all activities in the same application
                       belong to a single task.

Monday, March 18, 13
Bringing Activities
                          to the Foreground
         •      Activities pop back to
                foreground as the user
                presses back button
         •      As an example in the
                figure
               •       Activity B gets
                       destroyed as soon as
                       user presses back
                       button
               •       Activity A comes to
                       the foreground
Monday, March 18, 13
Task in the Background




        •      Application 1 Launches in Task A
        •      Home Screen     Task A Goes to the Background
        •      Application 2 Launches in Task B in the foreground
Monday, March 18, 13
Modifying Activity Launch
                  Behavior using Manifest Flags




Monday, March 18, 13
Activity Launch Mode

                       •   Activities can be configured to launch with the
                           following modes in the Manifest file

                                  Use Case              Launch Mode

                                                         standard
                                   Normal
                                                         singleTop

                                                         singleTask
                                  Specialized
                                                       singleInstance




Monday, March 18, 13
Activity Launch Mode
                                standard
  <activity               android: launchMode=”standard”/>


   •       Default Launch
           Mode

   •       All the Activities
           belong to the
           same task in the
           application



Monday, March 18, 13
Activity Launch Mode
                                    singleTop
       <activity
           android:launchMode=”singleTop”/>

     •      Single instance of an
            Activity can exist at
            the top of the back
            stack

     •      Multiple instances can
            exist if there are
            activities between
            them



Monday, March 18, 13
Activity Launch Mode
                                 singleTask

      <activity android:launchMode=”singleTask”/>


     •      Activity is the root of a
            task

     •      Other activities are part
            of this task if they are
            launched from this activity

     •      If this activity already
            exists Intent is routed to
            that Instance


Monday, March 18, 13
Activity Launch Mode
                           singleTask...contd

     •      If this activity
            already exists
            Intent is routed to
            that instance and
            onNewIntent()
            Lifecycle method
            is called




Monday, March 18, 13
Activity Launch Mode
                                  singleInstance
     <activity
          android:launchMode=”singleInstance”/>

      •       Activity B is launched
              with launchMode
              singleInstance, it is
              always the only
              activity of its task




Monday, March 18, 13
SingleTop using Intent Flags

                •      Single Instance of an Activity at the top of the back
                       stack can also be achieved using Intent Flags.
         Step 1 : Create Activity A using an Intent with no flag


                 Intent intentA = new Intent(MainActivity.this,
                 ActivityA.class);
                 startActivity(intentA);


         Step 2 : Create Activity A again with the Intent flag FLAG_ACTIVITY_SINGLE_TOP
             Intent intentA = new Intent(MainActivity.this,
             ActivityA.class);
             intentA.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
             startActivity(intentA);


Monday, March 18, 13
Other Behaviors..

                       •   No History on the Back stack

                       •   Task Reset and clearing the
                           Back Stack

                       •   Task Affinity attribute in
                           Manifest




Monday, March 18, 13
No History on the Back Stack
   •       An Activity can be set to have no history on the back stack - it will be destroyed
           as soon as user moves away from it using the the intent flag
           FLAG_ACTIVITY_NO_HISTORY




Monday, March 18, 13
Clear Activity on Task Reset


         •      Activities can be cleared from the back stack when a
                task is reset.
              •        Use the Intent Flags FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
                       and FLAG_ACTIVITY_RESET_TASK_IF_NEEDED are used together
                       to clear activities on a task reset.

                       •   Flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET  to indicate
                           that the activity will be destroyed when the task is reset.

                       •   Flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED refers to the activity in
                           the back stack beyond which activities are destroyed.




Monday, March 18, 13
Clear Activity on Task Reset
                       ..contd




Monday, March 18, 13
Clear Activity on Task Reset
                               Sample Code

               //Code below shows how the Activity A gets launched with
               the appropriate flags.
               Intent intentA = new Intent(MainActivity.this,
               ActivityA.class);
               intentA.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
               ;
               startActivity(intentA);

               //sample code below shows the flag with with Activity B and
               Activity C get launched.
               Intent intentB = new Intent(ActivityA.this,
               ActivityB.class);
               intentB.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
               );
               startActivity(intentB);


Monday, March 18, 13
TaskAffinity

                •      Task Affinity can be used to launch activities in a new task, e.g
                       having two Launcher Activities which need to have their own task

                •      EntryActivityA and EntryActivityB will Launch in their own tasks




Monday, March 18, 13
TaskAffinity
                                              ..contd

                       •   EntryActivityA and EntryActivityB will Launch in
                           their own tasks

                       •   Manifest file entries for the two activities
                       <activity android:name=".EntryActivityA"
                               android:label="@string/activitya"
                               android:taskAffinity="stacksample.activitya">
                           <intent-filter>
                               <action android:name="android.intent.action.MAIN" />
                               <category android:name="android.intent.category.LAUNCHER" />
                           </intent-filter>
                       </activity>
                       <activity android:name=".EntryActivityB"
                               android:label="@string/activityb"
                               android:taskAffinity="stacksample.activityb">
                           <intent-filter>
                               <action android:name="android.intent.action.MAIN" />
                               <category android:name="android.intent.category.LAUNCHER" />
                           </intent-filter>
                       </activity>



Monday, March 18, 13
Summary


                       •   Default behavior of using the back stack serves
                           most of the use cases

                       •   Default behavior can be modified using Manifest
                           file attributes and Intent flags to launch activities in
                           their own task, having a single instance or having
                           no history




Monday, March 18, 13

Contenu connexe

Tendances

Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-polimi
 
Interactive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsInteractive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsJuriy Zaytsev
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewYu-Hsin Hung
 
Heap and stack space in java
Heap and stack space in javaHeap and stack space in java
Heap and stack space in javaTalha Ocakçı
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera ArchitecturePicker Weng
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observablesStefan Charsley
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 

Tendances (20)

Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Fragment
Fragment Fragment
Fragment
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Applied Computer Science Concepts in Android
Applied Computer Science Concepts in AndroidApplied Computer Science Concepts in Android
Applied Computer Science Concepts in Android
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
Interactive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsInteractive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.js
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 
Heap and stack space in java
Heap and stack space in javaHeap and stack space in java
Heap and stack space in java
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera Architecture
 
Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Golang
GolangGolang
Golang
 
android layouts
android layoutsandroid layouts
android layouts
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 

En vedette

Android application model
Android application modelAndroid application model
Android application modelmagicshui
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin WritingSchalk Cronjé
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJavaSanjay Acharya
 
Streams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxStreams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxAndrzej Sitek
 
Android Pro Tips - IO 13 reloaded Event
Android Pro Tips - IO 13 reloaded EventAndroid Pro Tips - IO 13 reloaded Event
Android Pro Tips - IO 13 reloaded EventRan Nachmany
 
PROMAND 2014 project structure
PROMAND 2014 project structurePROMAND 2014 project structure
PROMAND 2014 project structureAlexey Buzdin
 
Code Signing with CPK
Code Signing with CPKCode Signing with CPK
Code Signing with CPKZhi Guan
 
Introduction to MidoNet
Introduction to MidoNetIntroduction to MidoNet
Introduction to MidoNetTaku Fukushima
 
Cloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , KeynoteCloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , Keynoterajdeep
 
RubyKaigi2014レポート
RubyKaigi2014レポートRubyKaigi2014レポート
RubyKaigi2014レポートgree_tech
 
Openstack meetup-pune-aug22-overview
Openstack meetup-pune-aug22-overviewOpenstack meetup-pune-aug22-overview
Openstack meetup-pune-aug22-overviewrajdeep
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espressoÉdipo Souza
 
Cloudfoundry Overview
Cloudfoundry OverviewCloudfoundry Overview
Cloudfoundry Overviewrajdeep
 
C# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentC# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentGill Cleeren
 

En vedette (20)

Android application model
Android application modelAndroid application model
Android application model
 
android activity
android activityandroid activity
android activity
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJava
 
Streams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxStreams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to Rx
 
Android Pro Tips - IO 13 reloaded Event
Android Pro Tips - IO 13 reloaded EventAndroid Pro Tips - IO 13 reloaded Event
Android Pro Tips - IO 13 reloaded Event
 
PROMAND 2014 project structure
PROMAND 2014 project structurePROMAND 2014 project structure
PROMAND 2014 project structure
 
Code Signing with CPK
Code Signing with CPKCode Signing with CPK
Code Signing with CPK
 
MidoNet deep dive
MidoNet deep diveMidoNet deep dive
MidoNet deep dive
 
Introduction to MidoNet
Introduction to MidoNetIntroduction to MidoNet
Introduction to MidoNet
 
Cloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , KeynoteCloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , Keynote
 
RubyKaigi2014レポート
RubyKaigi2014レポートRubyKaigi2014レポート
RubyKaigi2014レポート
 
Gunosy.go #4 go
Gunosy.go #4 goGunosy.go #4 go
Gunosy.go #4 go
 
Openstack meetup-pune-aug22-overview
Openstack meetup-pune-aug22-overviewOpenstack meetup-pune-aug22-overview
Openstack meetup-pune-aug22-overview
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espresso
 
AML workshop - Status of caller location and 112
AML workshop - Status of caller location and 112AML workshop - Status of caller location and 112
AML workshop - Status of caller location and 112
 
Cloudfoundry Overview
Cloudfoundry OverviewCloudfoundry Overview
Cloudfoundry Overview
 
Om
OmOm
Om
 
C# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentC# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform development
 
rtnetlink
rtnetlinkrtnetlink
rtnetlink
 

Plus de rajdeep

Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overviewrajdeep
 
Docker 1.5
Docker 1.5Docker 1.5
Docker 1.5rajdeep
 
Docker Swarm Introduction
Docker Swarm IntroductionDocker Swarm Introduction
Docker Swarm Introductionrajdeep
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetesrajdeep
 
Docker Architecture (v1.3)
Docker Architecture (v1.3)Docker Architecture (v1.3)
Docker Architecture (v1.3)rajdeep
 
Openstack Overview
Openstack OverviewOpenstack Overview
Openstack Overviewrajdeep
 
virtualization-vs-containerization-paas
virtualization-vs-containerization-paasvirtualization-vs-containerization-paas
virtualization-vs-containerization-paasrajdeep
 
VMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - OverviewVMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - Overviewrajdeep
 
OpenvSwitch Deep Dive
OpenvSwitch Deep DiveOpenvSwitch Deep Dive
OpenvSwitch Deep Diverajdeep
 
Deploy Cloud Foundry using bosh_bootstrap
Deploy Cloud Foundry using bosh_bootstrapDeploy Cloud Foundry using bosh_bootstrap
Deploy Cloud Foundry using bosh_bootstraprajdeep
 
Cloud Foundry Architecture and Overview
Cloud Foundry Architecture and OverviewCloud Foundry Architecture and Overview
Cloud Foundry Architecture and Overviewrajdeep
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundryrajdeep
 
Google cloud platform
Google cloud platformGoogle cloud platform
Google cloud platformrajdeep
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Enginerajdeep
 

Plus de rajdeep (14)

Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overview
 
Docker 1.5
Docker 1.5Docker 1.5
Docker 1.5
 
Docker Swarm Introduction
Docker Swarm IntroductionDocker Swarm Introduction
Docker Swarm Introduction
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
Docker Architecture (v1.3)
Docker Architecture (v1.3)Docker Architecture (v1.3)
Docker Architecture (v1.3)
 
Openstack Overview
Openstack OverviewOpenstack Overview
Openstack Overview
 
virtualization-vs-containerization-paas
virtualization-vs-containerization-paasvirtualization-vs-containerization-paas
virtualization-vs-containerization-paas
 
VMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - OverviewVMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - Overview
 
OpenvSwitch Deep Dive
OpenvSwitch Deep DiveOpenvSwitch Deep Dive
OpenvSwitch Deep Dive
 
Deploy Cloud Foundry using bosh_bootstrap
Deploy Cloud Foundry using bosh_bootstrapDeploy Cloud Foundry using bosh_bootstrap
Deploy Cloud Foundry using bosh_bootstrap
 
Cloud Foundry Architecture and Overview
Cloud Foundry Architecture and OverviewCloud Foundry Architecture and Overview
Cloud Foundry Architecture and Overview
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Google cloud platform
Google cloud platformGoogle cloud platform
Google cloud platform
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 

Dernier

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Managing Activity Backstack

  • 1. Managing Android Back stack Rajdeep Dua June 2012 Monday, March 18, 13
  • 2. Agenda • Activity Back Stack explained • Tasks • Bringing activities to the foreground • Modifying Activity launch behavior using manifest file attributes • Other advanced behaviors • No History • Task Reset • Task Affinity Monday, March 18, 13
  • 3. Android Back Stack • An Android application is composed of multiple activities • New Activities are launched using Intents • Older ones are either destroyed or placed on a back stack Monday, March 18, 13
  • 4. Android Back Stack • New Activity can be launched in the same task or a new task • Back stack is a data structure which holds activities in the background which user can navigate to using back button. • Back Stack works in the last in first out mode. • It can be cleared in case of low memory Monday, March 18, 13
  • 5. Tasks • Task is a collection of activities that user performs while doing a job • An activity is launched in a new task from the Home screen • By default all the activities in an application belong to the same task • Activities in a task can exist in the foreground, background as well as on the back stack. Monday, March 18, 13
  • 6. Tasks Activity A and Activity B are launched in Task A. By default all activities in the same application belong to a single task. Monday, March 18, 13
  • 7. Bringing Activities to the Foreground • Activities pop back to foreground as the user presses back button • As an example in the figure • Activity B gets destroyed as soon as user presses back button • Activity A comes to the foreground Monday, March 18, 13
  • 8. Task in the Background • Application 1 Launches in Task A • Home Screen Task A Goes to the Background • Application 2 Launches in Task B in the foreground Monday, March 18, 13
  • 9. Modifying Activity Launch Behavior using Manifest Flags Monday, March 18, 13
  • 10. Activity Launch Mode • Activities can be configured to launch with the following modes in the Manifest file Use Case Launch Mode standard Normal singleTop singleTask Specialized singleInstance Monday, March 18, 13
  • 11. Activity Launch Mode standard <activity android: launchMode=”standard”/> • Default Launch Mode • All the Activities belong to the same task in the application Monday, March 18, 13
  • 12. Activity Launch Mode singleTop <activity android:launchMode=”singleTop”/> • Single instance of an Activity can exist at the top of the back stack • Multiple instances can exist if there are activities between them Monday, March 18, 13
  • 13. Activity Launch Mode singleTask <activity android:launchMode=”singleTask”/> • Activity is the root of a task • Other activities are part of this task if they are launched from this activity • If this activity already exists Intent is routed to that Instance Monday, March 18, 13
  • 14. Activity Launch Mode singleTask...contd • If this activity already exists Intent is routed to that instance and onNewIntent() Lifecycle method is called Monday, March 18, 13
  • 15. Activity Launch Mode singleInstance <activity android:launchMode=”singleInstance”/> • Activity B is launched with launchMode singleInstance, it is always the only activity of its task Monday, March 18, 13
  • 16. SingleTop using Intent Flags • Single Instance of an Activity at the top of the back stack can also be achieved using Intent Flags. Step 1 : Create Activity A using an Intent with no flag Intent intentA = new Intent(MainActivity.this, ActivityA.class); startActivity(intentA); Step 2 : Create Activity A again with the Intent flag FLAG_ACTIVITY_SINGLE_TOP Intent intentA = new Intent(MainActivity.this, ActivityA.class); intentA.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) startActivity(intentA); Monday, March 18, 13
  • 17. Other Behaviors.. • No History on the Back stack • Task Reset and clearing the Back Stack • Task Affinity attribute in Manifest Monday, March 18, 13
  • 18. No History on the Back Stack • An Activity can be set to have no history on the back stack - it will be destroyed as soon as user moves away from it using the the intent flag FLAG_ACTIVITY_NO_HISTORY Monday, March 18, 13
  • 19. Clear Activity on Task Reset • Activities can be cleared from the back stack when a task is reset. • Use the Intent Flags FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET and FLAG_ACTIVITY_RESET_TASK_IF_NEEDED are used together to clear activities on a task reset. • Flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET  to indicate that the activity will be destroyed when the task is reset. • Flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED refers to the activity in the back stack beyond which activities are destroyed. Monday, March 18, 13
  • 20. Clear Activity on Task Reset ..contd Monday, March 18, 13
  • 21. Clear Activity on Task Reset Sample Code //Code below shows how the Activity A gets launched with the appropriate flags. Intent intentA = new Intent(MainActivity.this, ActivityA.class); intentA.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) ; startActivity(intentA); //sample code below shows the flag with with Activity B and Activity C get launched. Intent intentB = new Intent(ActivityA.this, ActivityB.class); intentB.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET ); startActivity(intentB); Monday, March 18, 13
  • 22. TaskAffinity • Task Affinity can be used to launch activities in a new task, e.g having two Launcher Activities which need to have their own task • EntryActivityA and EntryActivityB will Launch in their own tasks Monday, March 18, 13
  • 23. TaskAffinity ..contd • EntryActivityA and EntryActivityB will Launch in their own tasks • Manifest file entries for the two activities <activity android:name=".EntryActivityA" android:label="@string/activitya" android:taskAffinity="stacksample.activitya"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".EntryActivityB" android:label="@string/activityb" android:taskAffinity="stacksample.activityb"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> Monday, March 18, 13
  • 24. Summary • Default behavior of using the back stack serves most of the use cases • Default behavior can be modified using Manifest file attributes and Intent flags to launch activities in their own task, having a single instance or having no history Monday, March 18, 13