SlideShare a Scribd company logo
Android activity launch modes and tasks Gonçalo Silva / Novoda
 
Co-organizer ~1250 members
Activity launch modes and tasks..
What is an Activity?
Main building block of Android applications
HelloWorldActivity.java public   class  HelloWorldActivity  extends  Activity { .... }
AndroidManifest.xml <? xml   version = &quot;1.0&quot;   encoding = &quot;utf-8&quot; ?> < manifest  xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; package = &quot;com.novoda.jax&quot; android:versionCode = &quot;1&quot; android:versionName = &quot;1.0&quot;   > < application   > < activity android:name = &quot;.HelloWorldActivity&quot;   />   </ application > </ manifest >
Activity task Sequence of related activities a user follows
 
 
 
 
Activity stack / back stack
How are activites started?
Messaging facility for late run-time binding between components Intents!
Intent object Action Data – URI and/or MIME type Category Extras – key/value pairs Component name Flags
Explicit intent resolution Intent intent =  new  Intent( this , HelloWorldActivity. class ); startActivity(intent);
Implicit intent resolution Uri google = Uri. parse ( &quot;http://www.google.com&quot; ); Intent intent =  new  Intent( Intent. ACTION_VIEW , google); startActivity(intent);
Intent filter < activity   android:name = &quot;.SimpleBrowser&quot;   > < intent-filter  > < action   android:name = &quot;android.intent.action.VIEW&quot;   /> < category   android:name = &quot;android.intent.category.DEFAULT&quot;   /> < data   android:scheme = &quot;http&quot;   /> </ intent-filter > </activity>
Intents are great! Loosely coupled activities Specify your behaviour as intentions
Activity re-use Starting an activity in a different application
Task Twitter
Task Twitter
Task Twitter Gmail
Activity re-use Some activities are started in a different task
Task A Gmail
Task A Gmail Task B Browser
Activity re-use Allows user to resume after leaving original task Why different tasks?
How can we resume an activity?
 
Resuming an activity
Resuming a “killed” activity
How can we choose a specific task behaviour for our activities?
Activity launch modes Define how a new instance of an activity is associated with the current task
Four launch modes standard singleTop singleTask singleInstance
Defined in the manifest < activity android:launchMode = &quot;singleTop&quot; android:name = &quot;.HelloWorldActivity&quot;   />
Set as a flag in an intent Intent intent =  new  Intent( this , HelloWorldActivity. class ); intent.addFlags(Intent. FLAG_ACTIVITY_SINGLE_TOP ); startActivity(intent);
Demo App!!! Search the market for: launchmode
standard – default launch mode
singleTop A new activity X will not be started if there is an activity X on top of the stack onNewIntent() will be called instead of the normal activity lifecycle
singleTask Created at the root of a new task Only one instance of the activity can exist at a time onNewIntent() is called if an instance of the activity already exists
singleInstance Like singleTop but the only member of its task Any activities started will open in a separate task.
Examples of launchModes singleTop: Dashboard, Search singleTask: Browser, Google Maps singleInstance: Home screen
Intent flags and launchModes
FLAG_ACTIVITY_SINGLE_TOP
FLAG_ACTIVITY_MULTIPLE_TASK FLAG_ACTIVITY_NEW_TASK Force an activity to a new task Not recommended!
FLAG_ACTIVITY_NO_HISTORY
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_REORDER_TO_FRONT
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS The new activity is not kept in the list of recently launched activities
FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
Other manifest attributes to help deal with activities and tasks
android:taskAffinity Useful to ensure certain activities are always in the same task By default, all activities in an application have the same affinity singleTask Gotcha!!!
android:allowTaskReparenting Next time an activity comes to the front, move it to a task it has an affinity for Eg: email and browser
android:clearTaskOnLaunch Clear all activities from the task except the root, when launching the app from the home screen Only honoured for activities that start a new task Can be combined with “allowTaskReparenting”
android:alwaysRetainTaskState The state of the task is mantained by the system, even after a long period of time Only honoured for activities that start a new task Eg: browser tabs
android:finishOnTaskLaunch Shut down an instance of an activity when its task is resumed Trumps android:alwaysRetainTaskState
singleTask and singleInstance change the UI flow Use with caution!
singleTask UI flow
 
 
 
singleInstance UI flow
 
 
 
 
 
Two launcher icons
Provide a launcher icon for each singleTask / singleInstance activity
Another disadvantage:  startActivityForResult()
Recommended launchModes: standard and singleTop with intent flags combinations will suit most use cases
To recap: Activities and how they live in tasks Intents and re-using activities in other apps Activity lifecycle and the four launchmodes Intent flags and manifest attributes singleTask and singleInstance disadvantages
Thank you for listening! Any Questions?

More Related Content

PDF
Manipulating Android tasks and back stack
PDF
Use Node.js to create a REST API
PDF
Android activity
PDF
Android activities & views
PDF
Explore Android Internals
PDF
Jetpack Compose beginner.pdf
PPTX
Introduction to Koltin for Android Part I
PDF
Android Basic Components
Manipulating Android tasks and back stack
Use Node.js to create a REST API
Android activity
Android activities & views
Explore Android Internals
Jetpack Compose beginner.pdf
Introduction to Koltin for Android Part I
Android Basic Components

What's hot (20)

PDF
React js t2 - jsx
PDF
Low Level View of Android System Architecture
PPT
The Kotlin Programming Language
PPTX
Android internals By Rajesh Khetan
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
PPTX
Spring data jpa
PDF
Analysing in depth work manager
PDF
PUC SE Day 2019 - SpringBoot
PDF
Android intents
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
PPT
SQLITE Android
PPT
Android lifecycle
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
PDF
Gradle Introduction
PPTX
Android Services
PDF
Introduction to Android Window System
PPTX
Database in Android
PDF
Android's HIDL: Treble in the HAL
PDF
Android Development - ConstraintLayout
PDF
Why and How to Use Virtual DOM
React js t2 - jsx
Low Level View of Android System Architecture
The Kotlin Programming Language
Android internals By Rajesh Khetan
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Spring data jpa
Analysing in depth work manager
PUC SE Day 2019 - SpringBoot
Android intents
Workshop 4: NodeJS. Express Framework & MongoDB.
SQLITE Android
Android lifecycle
Asynchronous JavaScript Programming with Callbacks & Promises
Gradle Introduction
Android Services
Introduction to Android Window System
Database in Android
Android's HIDL: Treble in the HAL
Android Development - ConstraintLayout
Why and How to Use Virtual DOM
Ad

Viewers also liked (20)

PDF
Managing Activity Backstack
PPTX
The android activity lifecycle
PDF
02 programmation mobile - android - (activity, view, fragment)
PPTX
Android Activity Transition(ShareElement)
PPTX
Android activity lifecycle
PPTX
Android ppt
PPT
android activity
PPT
Android activity, service, and broadcast recievers
PDF
AIDL - Android Interface Definition Language
PPTX
IPC: AIDL is not a curse
PPTX
Android case: 5 perguntas + 1 sobre desenvolvimento para Android
PPT
Desenvolvimento para Android
ODP
Meu primeiro app nativo para Android - Minicurso SCTI UENF
PDF
Desenvolvimento android
PPTX
1ª aula - Teste
PPTX
Criando app mobile com Google Android - Software Freedom Day 2015
PPT
Pie.157055.ioc grupo 3 - android e i os
PPTX
Google android Activity lifecycle
PDF
Android Logging System
ODP
Aula teste ETEC - Analise de Programacao
Managing Activity Backstack
The android activity lifecycle
02 programmation mobile - android - (activity, view, fragment)
Android Activity Transition(ShareElement)
Android activity lifecycle
Android ppt
android activity
Android activity, service, and broadcast recievers
AIDL - Android Interface Definition Language
IPC: AIDL is not a curse
Android case: 5 perguntas + 1 sobre desenvolvimento para Android
Desenvolvimento para Android
Meu primeiro app nativo para Android - Minicurso SCTI UENF
Desenvolvimento android
1ª aula - Teste
Criando app mobile com Google Android - Software Freedom Day 2015
Pie.157055.ioc grupo 3 - android e i os
Google android Activity lifecycle
Android Logging System
Aula teste ETEC - Analise de Programacao
Ad

Similar to Android | Android Activity Launch Modes and Tasks | Gonçalo Silva (20)

PPT
21 android2 updated
PPT
Multiple Activity and Navigation Primer
PPTX
Lecture #1 Creating your first android project
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
DOCX
Activity
DOCX
Activity
DOCX
Activity
DOCX
Activity
PPTX
Architecting Single Activity Applications (With or Without Fragments)
PPTX
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
PDF
The activity class
PDF
The activity class
PPTX
04 activities - Android
PDF
Introduction to State Restoration in Flutter
PDF
Android session 2
ODP
Разработка приложений для Android Honeycomb: ActionBar & Fragments
DOCX
Android building blocks and application life cycle-chapter3
DOCX
Practical 14 android.docx
PPTX
Developing Android Apps
PDF
Mad textbook 63-116
21 android2 updated
Multiple Activity and Navigation Primer
Lecture #1 Creating your first android project
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
Activity
Activity
Activity
Activity
Architecting Single Activity Applications (With or Without Fragments)
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
The activity class
The activity class
04 activities - Android
Introduction to State Restoration in Flutter
Android session 2
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Android building blocks and application life cycle-chapter3
Practical 14 android.docx
Developing Android Apps
Mad textbook 63-116

More from JAX London (20)

PDF
Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
ODP
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
PDF
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
PDF
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
PDF
Spring Day | Behind the Scenes at Spring Batch | Dave Syer
PDF
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
PDF
Spring Day | Identity Management with Spring Security | Dave Syer
PDF
Spring Day | Spring and Scala | Eberhard Wolff
PDF
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
PPT
Keynote | The Rise and Fall and Rise of Java | James Governor
ODP
Java Tech & Tools | OSGi Best Practices | Emily Jiang
PPTX
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
PDF
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
PDF
Java Tech & Tools | Social Media in Programming in Java | Khanderao Kand
PDF
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
PDF
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
PDF
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
ODP
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
PDF
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
KEY
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | Behind the Scenes at Spring Batch | Dave Syer
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Identity Management with Spring Security | Dave Syer
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
Keynote | The Rise and Fall and Rise of Java | James Governor
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Social Media in Programming in Java | Khanderao Kand
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...

Recently uploaded (20)

PDF
August Patch Tuesday
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Tartificialntelligence_presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Machine learning based COVID-19 study performance prediction
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
A Presentation on Artificial Intelligence
PDF
Mushroom cultivation and it's methods.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Approach and Philosophy of On baking technology
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Machine Learning_overview_presentation.pptx
August Patch Tuesday
OMC Textile Division Presentation 2021.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Tartificialntelligence_presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Assigned Numbers - 2025 - Bluetooth® Document
Machine learning based COVID-19 study performance prediction
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Empathic Computing: Creating Shared Understanding
Heart disease approach using modified random forest and particle swarm optimi...
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
A Presentation on Artificial Intelligence
Mushroom cultivation and it's methods.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Building Integrated photovoltaic BIPV_UPV.pdf
Approach and Philosophy of On baking technology
A comparative study of natural language inference in Swahili using monolingua...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Machine Learning_overview_presentation.pptx

Android | Android Activity Launch Modes and Tasks | Gonçalo Silva