SlideShare ist ein Scribd-Unternehmen logo
1 von 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
                       le 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
                gure
               •       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 le

                                  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
TaskAfnity

                •      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
TaskAfnity
                                              ..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

Weitere ähnliche Inhalte

Was ist angesagt?

Job schedulers android
Job schedulers androidJob schedulers android
Job schedulers androidDeesha Vora
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Atif AbbAsi
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorageKrazy Koder
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosuĂŠ Neis
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologiesjerry vasoya
 
Methods in java
Methods in javaMethods in java
Methods in javachauhankapil
 
Dalvik Vm &amp; Jit
Dalvik Vm &amp; JitDalvik Vm &amp; Jit
Dalvik Vm &amp; JitAnkit Somani
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesHùng Nguyễn Huy
 
Google Maps in Android
Google Maps in AndroidGoogle Maps in Android
Google Maps in AndroidMobile 2.0 Europe
 
Android resources
Android resourcesAndroid resources
Android resourcesma-polimi
 
Maps in android
Maps in androidMaps in android
Maps in androidSumita Das
 

Was ist angesagt? (20)

Job schedulers android
Job schedulers androidJob schedulers android
Job schedulers android
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Android life cycle
Android life cycleAndroid life cycle
Android life cycle
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Dalvik Vm &amp; Jit
Dalvik Vm &amp; JitDalvik Vm &amp; Jit
Dalvik Vm &amp; Jit
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Google Maps in Android
Google Maps in AndroidGoogle Maps in Android
Google Maps in Android
 
Android resources
Android resourcesAndroid resources
Android resources
 
Maps in android
Maps in androidMaps in android
Maps in android
 
Android intents
Android intentsAndroid intents
Android intents
 

Andere mochten auch

Android application model
Android application modelAndroid application model
Android application modelmagicshui
 
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
 
MidoNet deep dive
MidoNet deep diveMidoNet deep dive
MidoNet deep diveTaku Fukushima
 
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
 
Openstack Overview
Openstack OverviewOpenstack Overview
Openstack Overviewrajdeep
 

Andere mochten auch (20)

Android application model
Android application modelAndroid application model
Android application model
 
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
 
Openstack Overview
Openstack OverviewOpenstack Overview
Openstack Overview
 

Mehr von 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
 
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
 

Mehr von rajdeep (13)

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)
 
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
 

KĂźrzlich hochgeladen

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
[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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

KĂźrzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

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 le attributes • Other advanced behaviors • No History • Task Reset • Task Afnity 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 rst 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 gure • 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 congured to launch with the following modes in the Manifest le 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 Afnity 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. TaskAfnity • Task Afnity 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. TaskAfnity ..contd • EntryActivityA and EntryActivityB will Launch in their own tasks • Manifest le 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 modied using Manifest le attributes and Intent flags to launch activities in their own task, having a single instance or having no history Monday, March 18, 13