SlideShare a Scribd company logo
1 of 53
Activities and Views
Ilio Catallo, Eleonora Ciceri – Politecnico di Milano
ilio.catallo@polimi.it, eleonora.ciceri@polimi.it
1
Androidinterface
2
Recent button
Jump instantly from
one task to another by
navigating a list of
recently opened apps
Home button
Visualize the Android
home screen
Back button
Move backward
through the history
of screens users
previously visited
Definitions
3
Activities and Views
¤ The activity is a single, focused thing that the user can do
¤ Each activity is associated with a window in which to draw
the user interface
¤ The view is the basic building block for user interface
components
¤ Responsible for drawing and event handling
¤ Examples: button, textbox
4
Applicationbuilding
blocks:UIcomponents
5
View
View
The Activity is the task
that can be
performed by
interacting with the
user interface
Analogy: web pages and activities
Website Application
6
Home
page
Main
activity
Navigation among
various pages
Navigation among
various activities
Activities and use case diagrams
¤ Roughly, each activity corresponds to a use case
¤ As such, the use case diagram could also serve as the
graph of connected activities
7
User
Use case 1
Use case 2
Use case 3
<includes>
Use case 4<includes>
Activity lifecycle
8
Activity lifecycle
¤ The activity lifecycle:
¤ Begins with instantiation
¤ Ends with destruction
¤ Includes many states in between
¤ Whenever a state change is required, the activity:
¤ is notified of the impending state change
¤ is allowed to execute the code in order to adapt itself to
that change
9
Activity lifecycle
¤ The state of each Activity is determined by its position on
the Activity stack
¤ The Activity stack is a last-in-first-out collection of all the
currently running activities
¤ When a new Activity starts, it becomes active and is moved
to the top of the stack
¤ If the user navigates back (using the Back button) or the
foreground Activity is closed, the next Activity down on the
stack moves up and becomes active
10
Activity lifecycle
¤ As Activities are created
and destroyed, they
transition through four
possible states:
¤ Active (running)
¤ Paused
¤ Stopped
¤ Inactive (destroyed)
11
FrontBack
Activity lifecycle
¤ Active (running) Activity
¤ Visible, focused,
foreground activity that
is receiving user input
¤ At the top of the stack
¤ Kept alive at all costs!
¤ If it does not have
the resources it
needs, other
Activities will be
killed
12
FrontBack
Activity lifecycle
¤ Paused Activity
¤ Visible but not focused
¤ This state is reached if a
transparent or non-full-
screen Activity is active
in front of it
¤ Treated as if it were
active, but without user
input events
13
FrontBack
Activity lifecycle
¤ Stopped Activity
¤ Not visible
¤ It remains in memory,
retaining all state
information
¤ It is a candidate for
termination when the
system requires memory
elsewhere
14
FrontBack
Activity lifecycle
¤ Inactive (destroyed)
Activity
¤ Removed from the
Activity stack
¤ Needs to be restarted
before it can be
displayed and used
15
FrontBack
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
16
onCreate()
onStart()
onResume()
onPause()
onResume()
onStop()
onRestart()
onStart()
onDestroy()
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
17
The activity does not
exist in memory
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
18
onCreate()
onStart()
onResume()
The activity is currently on
the screen and interacting
with the user
Create views, initialize variables
Actions performed at the end of
onCreate(), right before displaying
the activity
Start animations, listen from
GPS/camera updates
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
19
onPause()
The activity is not in focus
but still visible on the screen
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
20
onResume()
A paused activity is
resumed when it returns
visible on the screen
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
21
onStop()
The activity is not
visible but in
memory, waiting
for the user to
restart it soon
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
22
onRestart()
onStart()
When the user requires an
interaction with a stopped
activity, it is restarted
Activitylifecycle
¤ The activity lifecycle is implemented as a collection
of methods the OS calls throughout the lifecycle of
an activity
23
onDestroy()
A destroyed activity is no
longer in memory. Before
the activity is destroyed, it
can perform some actions
Differences between Home and Back
¤ When user presses Back
¤ The activity is destroyed
¤ Operations: onPause() – onStop() – onDestroy()
¤ When user presses Home
¤ The foreground activity is NOT destroyed
¤ Operations: onPause() – onStop()
¤ Note: the behavior in the emulator may differ
24
Configuration changes
¤ Configuration changes are rapid activity destruction/re-
creation cycles that occur when the configuration of an
activity changes
¤ Examples
¤ Device rotation: the activity needs to be rebuilt
¤ Keyboard is displayed: the activity is resized
25
Implementing lifecycle methods
¤ It is extremely important for the application developer to:
¤ analyze the requirements of each activity
¤ determine which methods need to be implemented
¤ Failure to do this can result in
¤ Application instability and crashes
¤ Resource bloat
¤ Underlying OS instability
¤ You should never call any lifecycle methods yourself!
26
TakeNotes v1:
ToDoListActivity.java
¤ Created as a default (blank) activity
¤ In Android Studio:
File > New > Other… > Android > Android Activity
27
public class ToDoListActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_do_list);
}
}
The file res/layout/activity_to_do_list.xml
defines the structure of the activity that is loaded
when the activity is created
Views and ViewGroups
28
User interface
¤ Each Activity in the app is associated with a user
interface (UI)
29
User interface
activity
User interface:
View and ViewGroup
¤ User interfaces are built using View’s and ViewGroup’s:
¤ A View is a widget that has an appearance on the screen
¤ A ViewGroup is a special View that contains other Views in
order to define the layout of the interface
¤ In other words, each ViewGroup is an invisible container
that organizes child Views, and Views are any widget
that draws some part of the UI
30
User interface:
View and ViewGroup
¤ The UI for each component of the app is defined using a
hierarchy of View and ViewGroup objects
31
User interface:
View and ViewGroup
¤ The UI for each component of the app is defined using a
hierarchy of View and ViewGroup objects
32
User interface layout
¤ Each subclass of ViewGroup defines the layout, i.e., the
arrangement, of its child views on the screen
33
LinearLayout RelativeLayout
User interface layout:
LinearLayout
¤ A LinearLayout
organizes its children
into:
¤ Either a single
horizontal row
¤ Or a single vertical
row
34
User interface layout:
RelativeLayout
¤ A RelativeLayout
enables you to
specify the location
of child objects:
¤ either relative to
each other
¤ or relative to the
parent
35
User interface:
View and ViewGroup
¤ Android provides a collection of View and ViewGroup
subclasses that cover most common situations:
¤ Views: input controls, e.g., TextView class, Button class,
CheckBox class
¤ ViewGroup: layout models, e.g., LinearLayout class,
RelativeLayout class
¤ However, if your app has unique need that is not
covered by the built-in views, it is possible to create a
custom View by extending the View class
36
LinearLayout ViewGroup
¤ The LinearLayout arranges views in a single column or a
single row
¤ Attributes
¤ layout_width: specifies the width of the ViewGroup
¤ layout_height: specifies the height of the ViewGroup
¤ orientation: vertical or horizontal
¤ Default values for attributes
¤ fill_parent: makes the component expand to match the
size of its parent view
¤ wrap_content: the width or height of the view is set to the
minimum size necessary to fit the content within that view
37
ScrollView ViewGroup
¤ The ScrollView enables users to scroll through a list of
views that occupy more space than the physical display
¤ You should place one child in it containing the entire
contents to scroll
¤ A child that is often used is LinearLayout, which in turn
contains some other views
¤ By doing so, the content of the LinearLayout will be
scrollable
38
ScrollView ViewGroup
39
Screen
ScrollView
width: fill_parent
height: fill_parent
LinearLayout
width: fill_parent
height: wrap_content
orientation: vertical
TakeNotes v1:
activity_to_do_list.xml
40
Add a static checkbox
to the checkbox list
A new string in the resource file specifies the content
of the default checkbox:
<string name="first_checkbox_text">
Conclude the implementation of TakeNotes
</string>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".ToDoListActivity">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox android:id="@+id/checkBox1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/first_checkbox_text"/>
</LinearLayout>
</ScrollView>
TakeNotes v1: the result
41
Resource
@drawable/ic_launcher
Resource
@string/app_name
View
Checkbox
Resource
@string/first_checkbox_text
Activity
ToDoListActivity.jav
a
Android vs. MVC
Patterns
¤ Patterns are distilled commonality that you find in
programs
¤ They provide a general solution to a class of problems
¤ Patterns allow developers to deconstruct a complex
system into smaller, simpler parts
43
Architectural vs. design
patterns
¤ Software goes through a series of deconstruction at
different levels
¤ Architectural patterns pertain to the structural organization
of software system
¤ Design patterns are associated with code level
commonalities, and can be influenced by the specific
programming language at use
44
Model-View-Controller
pattern
¤ In the late seventies, software architects saw applications
as having three major parts:
¤ The part that manages the data (Model)
¤ The part that creates screens and reports (View)
¤ The part that handles interactions between the user and the
other subsystems (Controller)
45
Model-View-Controller
pattern
46
View
Controller
Model
State query
Change notification
State
change
View
SelectionUserinteraction
Event
Method
invocation
MVC is a concept
¤ Remember: there is no universal MVC pattern. MVC is a
concept rather than a solid pattern
¤ In fact, it is not even clear whether MVC is a design
pattern or an architectural pattern
47
Many MVC declinations
¤ As a rule of thumb, you are adopting the MVC pattern if
the application includes:
¤ A set of classes containing what to render (Model)
¤ A set of classes that know how to render those data (View)
¤ A set of classes that contains the interaction logic
(Controller)
48
Android vs. MVC
¤ Android does not explicitly embrace MVC
¤ Still, some developers prefer to frame Android app
development within the precepts of the MVC pattern
49
Android MVC declination
50
User input
View Controller
User interacts with
view object
View sends message to
controller
Model
controller updates
model objects
controller takes
from model
objects data
needed by the
views
controller updates
view with changes
in the model
objects
TakeNotesvs.MVC
51
TextView Button Checkbox
Checkbox
Checkbox
ToDoListActivity
Todo
Todo
Todo
Model
Controller
View
The model objects hold
the data and the
business logic of the
app
the controller responds to
the events triggered by
view objects and
manage the flow of data
to and from model
objects
View objects know how
to draw themselves on
the screen and how to
respond to user input
References
52
References
¤ Android API Guides, UI Overview
http://developer.android.com/guide/topics/ui/overview.
html
¤ Android API Guides,
Layoutshttp://developer.android.com/guide/topics/ui/d
eclaring-layout.html
¤ Google I/O 2013 - Structure in Android App Design
https://www.youtube.com/watch?v=XpqyiBR0lJ4
¤ The Big Nerd Ranch Guide to Android Programming, B.
Phillips, B. Hardy
53

More Related Content

What's hot

Introduction to android
Introduction to androidIntroduction to android
Introduction to androidzeelpatel0504
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studioParinita03
 
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
 
Mobile application development
Mobile application developmentMobile application development
Mobile application developmentEric Cattoir
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in androidPrawesh Shrestha
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
Introduction to Android ppt
Introduction to Android pptIntroduction to Android ppt
Introduction to Android pptTaha Malampatti
 
Android application structure
Android application structureAndroid application structure
Android application structureAlexey Ustenko
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installationPoojaBele1
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-polimi
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development pptsaitej15
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application DevelopmentBenny Skogberg
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-polimi
 

What's hot (20)

Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
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
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Notification android
Notification androidNotification android
Notification android
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
 
Introduction to Android ppt
Introduction to Android pptIntroduction to Android ppt
Introduction to Android ppt
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installation
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
Google Maps in Android
Google Maps in AndroidGoogle Maps in Android
Google Maps in Android
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installation
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 

Viewers also liked

Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAhsanul Karim
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in androidJay Kumarr
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material DesignYasin Yildirim
 
Gradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of FriendsGradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of FriendsRomin Irani
 
Gradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionGradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionKevin Pelgrims
 
The Journey to conversational interfaces
The Journey to conversational interfacesThe Journey to conversational interfaces
The Journey to conversational interfacesRomin Irani
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesAhsanul Karim
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycleSoham Patel
 

Viewers also liked (9)

Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material Design
 
Gradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of FriendsGradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of Friends
 
Gradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionGradle & Android Studio - Introduction
Gradle & Android Studio - Introduction
 
The Journey to conversational interfaces
The Journey to conversational interfacesThe Journey to conversational interfaces
The Journey to conversational interfaces
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 

Similar to Android activities & views

11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docPalakjaiswal43
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android Component.pptx
Android Component.pptxAndroid Component.pptx
Android Component.pptxQwerty140857
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116PrathishGM
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 

Similar to Android activities & views (20)

11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Android
AndroidAndroid
Android
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
Mobile application development: part 1: Andriod Vs IOS
Mobile application development: part 1: Andriod Vs IOS Mobile application development: part 1: Andriod Vs IOS
Mobile application development: part 1: Andriod Vs IOS
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.doc
 
Android activity
Android activityAndroid activity
Android activity
 
Android activity
Android activityAndroid activity
Android activity
 
Android Component.pptx
Android Component.pptxAndroid Component.pptx
Android Component.pptx
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
android activity
android activityandroid activity
android activity
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 

More from ma-polimi

Android resources
Android resourcesAndroid resources
Android resourcesma-polimi
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Androidma-polimi
 
Persistence in Android
Persistence in AndroidPersistence in Android
Persistence in Androidma-polimi
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifestma-polimi
 
Introduction To Android
Introduction To AndroidIntroduction To Android
Introduction To Androidma-polimi
 

More from ma-polimi (6)

Android resources
Android resourcesAndroid resources
Android resources
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Android
 
Persistence in Android
Persistence in AndroidPersistence in Android
Persistence in Android
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifest
 
TakeNotes
TakeNotesTakeNotes
TakeNotes
 
Introduction To Android
Introduction To AndroidIntroduction To Android
Introduction To Android
 

Recently uploaded

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 

Recently uploaded (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 

Android activities & views

  • 1. Activities and Views Ilio Catallo, Eleonora Ciceri – Politecnico di Milano ilio.catallo@polimi.it, eleonora.ciceri@polimi.it 1
  • 2. Androidinterface 2 Recent button Jump instantly from one task to another by navigating a list of recently opened apps Home button Visualize the Android home screen Back button Move backward through the history of screens users previously visited
  • 4. Activities and Views ¤ The activity is a single, focused thing that the user can do ¤ Each activity is associated with a window in which to draw the user interface ¤ The view is the basic building block for user interface components ¤ Responsible for drawing and event handling ¤ Examples: button, textbox 4
  • 5. Applicationbuilding blocks:UIcomponents 5 View View The Activity is the task that can be performed by interacting with the user interface
  • 6. Analogy: web pages and activities Website Application 6 Home page Main activity Navigation among various pages Navigation among various activities
  • 7. Activities and use case diagrams ¤ Roughly, each activity corresponds to a use case ¤ As such, the use case diagram could also serve as the graph of connected activities 7 User Use case 1 Use case 2 Use case 3 <includes> Use case 4<includes>
  • 9. Activity lifecycle ¤ The activity lifecycle: ¤ Begins with instantiation ¤ Ends with destruction ¤ Includes many states in between ¤ Whenever a state change is required, the activity: ¤ is notified of the impending state change ¤ is allowed to execute the code in order to adapt itself to that change 9
  • 10. Activity lifecycle ¤ The state of each Activity is determined by its position on the Activity stack ¤ The Activity stack is a last-in-first-out collection of all the currently running activities ¤ When a new Activity starts, it becomes active and is moved to the top of the stack ¤ If the user navigates back (using the Back button) or the foreground Activity is closed, the next Activity down on the stack moves up and becomes active 10
  • 11. Activity lifecycle ¤ As Activities are created and destroyed, they transition through four possible states: ¤ Active (running) ¤ Paused ¤ Stopped ¤ Inactive (destroyed) 11 FrontBack
  • 12. Activity lifecycle ¤ Active (running) Activity ¤ Visible, focused, foreground activity that is receiving user input ¤ At the top of the stack ¤ Kept alive at all costs! ¤ If it does not have the resources it needs, other Activities will be killed 12 FrontBack
  • 13. Activity lifecycle ¤ Paused Activity ¤ Visible but not focused ¤ This state is reached if a transparent or non-full- screen Activity is active in front of it ¤ Treated as if it were active, but without user input events 13 FrontBack
  • 14. Activity lifecycle ¤ Stopped Activity ¤ Not visible ¤ It remains in memory, retaining all state information ¤ It is a candidate for termination when the system requires memory elsewhere 14 FrontBack
  • 15. Activity lifecycle ¤ Inactive (destroyed) Activity ¤ Removed from the Activity stack ¤ Needs to be restarted before it can be displayed and used 15 FrontBack
  • 16. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 16 onCreate() onStart() onResume() onPause() onResume() onStop() onRestart() onStart() onDestroy()
  • 17. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 17 The activity does not exist in memory
  • 18. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 18 onCreate() onStart() onResume() The activity is currently on the screen and interacting with the user Create views, initialize variables Actions performed at the end of onCreate(), right before displaying the activity Start animations, listen from GPS/camera updates
  • 19. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 19 onPause() The activity is not in focus but still visible on the screen
  • 20. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 20 onResume() A paused activity is resumed when it returns visible on the screen
  • 21. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 21 onStop() The activity is not visible but in memory, waiting for the user to restart it soon
  • 22. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 22 onRestart() onStart() When the user requires an interaction with a stopped activity, it is restarted
  • 23. Activitylifecycle ¤ The activity lifecycle is implemented as a collection of methods the OS calls throughout the lifecycle of an activity 23 onDestroy() A destroyed activity is no longer in memory. Before the activity is destroyed, it can perform some actions
  • 24. Differences between Home and Back ¤ When user presses Back ¤ The activity is destroyed ¤ Operations: onPause() – onStop() – onDestroy() ¤ When user presses Home ¤ The foreground activity is NOT destroyed ¤ Operations: onPause() – onStop() ¤ Note: the behavior in the emulator may differ 24
  • 25. Configuration changes ¤ Configuration changes are rapid activity destruction/re- creation cycles that occur when the configuration of an activity changes ¤ Examples ¤ Device rotation: the activity needs to be rebuilt ¤ Keyboard is displayed: the activity is resized 25
  • 26. Implementing lifecycle methods ¤ It is extremely important for the application developer to: ¤ analyze the requirements of each activity ¤ determine which methods need to be implemented ¤ Failure to do this can result in ¤ Application instability and crashes ¤ Resource bloat ¤ Underlying OS instability ¤ You should never call any lifecycle methods yourself! 26
  • 27. TakeNotes v1: ToDoListActivity.java ¤ Created as a default (blank) activity ¤ In Android Studio: File > New > Other… > Android > Android Activity 27 public class ToDoListActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_to_do_list); } } The file res/layout/activity_to_do_list.xml defines the structure of the activity that is loaded when the activity is created
  • 29. User interface ¤ Each Activity in the app is associated with a user interface (UI) 29 User interface activity
  • 30. User interface: View and ViewGroup ¤ User interfaces are built using View’s and ViewGroup’s: ¤ A View is a widget that has an appearance on the screen ¤ A ViewGroup is a special View that contains other Views in order to define the layout of the interface ¤ In other words, each ViewGroup is an invisible container that organizes child Views, and Views are any widget that draws some part of the UI 30
  • 31. User interface: View and ViewGroup ¤ The UI for each component of the app is defined using a hierarchy of View and ViewGroup objects 31
  • 32. User interface: View and ViewGroup ¤ The UI for each component of the app is defined using a hierarchy of View and ViewGroup objects 32
  • 33. User interface layout ¤ Each subclass of ViewGroup defines the layout, i.e., the arrangement, of its child views on the screen 33 LinearLayout RelativeLayout
  • 34. User interface layout: LinearLayout ¤ A LinearLayout organizes its children into: ¤ Either a single horizontal row ¤ Or a single vertical row 34
  • 35. User interface layout: RelativeLayout ¤ A RelativeLayout enables you to specify the location of child objects: ¤ either relative to each other ¤ or relative to the parent 35
  • 36. User interface: View and ViewGroup ¤ Android provides a collection of View and ViewGroup subclasses that cover most common situations: ¤ Views: input controls, e.g., TextView class, Button class, CheckBox class ¤ ViewGroup: layout models, e.g., LinearLayout class, RelativeLayout class ¤ However, if your app has unique need that is not covered by the built-in views, it is possible to create a custom View by extending the View class 36
  • 37. LinearLayout ViewGroup ¤ The LinearLayout arranges views in a single column or a single row ¤ Attributes ¤ layout_width: specifies the width of the ViewGroup ¤ layout_height: specifies the height of the ViewGroup ¤ orientation: vertical or horizontal ¤ Default values for attributes ¤ fill_parent: makes the component expand to match the size of its parent view ¤ wrap_content: the width or height of the view is set to the minimum size necessary to fit the content within that view 37
  • 38. ScrollView ViewGroup ¤ The ScrollView enables users to scroll through a list of views that occupy more space than the physical display ¤ You should place one child in it containing the entire contents to scroll ¤ A child that is often used is LinearLayout, which in turn contains some other views ¤ By doing so, the content of the LinearLayout will be scrollable 38
  • 39. ScrollView ViewGroup 39 Screen ScrollView width: fill_parent height: fill_parent LinearLayout width: fill_parent height: wrap_content orientation: vertical
  • 40. TakeNotes v1: activity_to_do_list.xml 40 Add a static checkbox to the checkbox list A new string in the resource file specifies the content of the default checkbox: <string name="first_checkbox_text"> Conclude the implementation of TakeNotes </string> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".ToDoListActivity"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <CheckBox android:id="@+id/checkBox1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="32dp" android:text="@string/first_checkbox_text"/> </LinearLayout> </ScrollView>
  • 41. TakeNotes v1: the result 41 Resource @drawable/ic_launcher Resource @string/app_name View Checkbox Resource @string/first_checkbox_text Activity ToDoListActivity.jav a
  • 43. Patterns ¤ Patterns are distilled commonality that you find in programs ¤ They provide a general solution to a class of problems ¤ Patterns allow developers to deconstruct a complex system into smaller, simpler parts 43
  • 44. Architectural vs. design patterns ¤ Software goes through a series of deconstruction at different levels ¤ Architectural patterns pertain to the structural organization of software system ¤ Design patterns are associated with code level commonalities, and can be influenced by the specific programming language at use 44
  • 45. Model-View-Controller pattern ¤ In the late seventies, software architects saw applications as having three major parts: ¤ The part that manages the data (Model) ¤ The part that creates screens and reports (View) ¤ The part that handles interactions between the user and the other subsystems (Controller) 45
  • 47. MVC is a concept ¤ Remember: there is no universal MVC pattern. MVC is a concept rather than a solid pattern ¤ In fact, it is not even clear whether MVC is a design pattern or an architectural pattern 47
  • 48. Many MVC declinations ¤ As a rule of thumb, you are adopting the MVC pattern if the application includes: ¤ A set of classes containing what to render (Model) ¤ A set of classes that know how to render those data (View) ¤ A set of classes that contains the interaction logic (Controller) 48
  • 49. Android vs. MVC ¤ Android does not explicitly embrace MVC ¤ Still, some developers prefer to frame Android app development within the precepts of the MVC pattern 49
  • 50. Android MVC declination 50 User input View Controller User interacts with view object View sends message to controller Model controller updates model objects controller takes from model objects data needed by the views controller updates view with changes in the model objects
  • 51. TakeNotesvs.MVC 51 TextView Button Checkbox Checkbox Checkbox ToDoListActivity Todo Todo Todo Model Controller View The model objects hold the data and the business logic of the app the controller responds to the events triggered by view objects and manage the flow of data to and from model objects View objects know how to draw themselves on the screen and how to respond to user input
  • 53. References ¤ Android API Guides, UI Overview http://developer.android.com/guide/topics/ui/overview. html ¤ Android API Guides, Layoutshttp://developer.android.com/guide/topics/ui/d eclaring-layout.html ¤ Google I/O 2013 - Structure in Android App Design https://www.youtube.com/watch?v=XpqyiBR0lJ4 ¤ The Big Nerd Ranch Guide to Android Programming, B. Phillips, B. Hardy 53