SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Yoshifumi Kawai
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
A Brief Intro to Microsoft Orleans
A Brief Intro to Microsoft OrleansA Brief Intro to Microsoft Orleans
A Brief Intro to Microsoft OrleansUri Goldstein
 
Gitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for GitGitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for GitMaulik Shah
 
Android animation
Android animationAndroid animation
Android animationKrazy Koder
 
Introduction to A-Frame
Introduction to A-FrameIntroduction to A-Frame
Introduction to A-FrameDaosheng Mu
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Sandro Mancuso
 
Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation ComponentŁukasz Ciupa
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)CODE WHITE GmbH
 
jemalloc 세미나
jemalloc 세미나jemalloc 세미나
jemalloc 세미나Jang Hoon
 
Analysing in depth work manager
Analysing in depth work managerAnalysing in depth work manager
Analysing in depth work managerbhatnagar.gaurav83
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Roman Elizarov
 

What's hot (20)

Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Android activity
Android activityAndroid activity
Android activity
 
A Brief Intro to Microsoft Orleans
A Brief Intro to Microsoft OrleansA Brief Intro to Microsoft Orleans
A Brief Intro to Microsoft Orleans
 
Gitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for GitGitflow - Branching and Merging Flow for Git
Gitflow - Branching and Merging Flow for Git
 
Android animation
Android animationAndroid animation
Android animation
 
Introduction to A-Frame
Introduction to A-FrameIntroduction to A-Frame
Introduction to A-Frame
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014
 
Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation Component
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
 
jemalloc 세미나
jemalloc 세미나jemalloc 세미나
jemalloc 세미나
 
Analysing in depth work manager
Analysing in depth work managerAnalysing in depth work manager
Analysing in depth work manager
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Introduction to android testing
Introduction to android testingIntroduction to android testing
Introduction to android testing
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 

Viewers also liked

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
 

Viewers also liked (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
 

More from 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
 

More from 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
 

Recently uploaded

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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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