SlideShare a Scribd company logo
1 of 41
Android
Basics of UI Applications
Bibliography
1. Wallace Jackson, Android Apps for Absolute
Beginners, Apress, 2017
2. Peter Späth, Learn Kotlin for Android
Development, Apress 2019
3. Android Application Fundamentals,
http://developer.android.com/guide/topics/f
undamentals.html
2
Let’s recap
• Android
– OS
– Platform
– Kernel
– User space libraries
– Dalvik / ART
– Android Libraries
– Applications
• Android Applications
– Types
– Security
3
Contents
• Task
• Manifest
• Context
• Activity
– Life cycle
– Activity types
– Components
• Containers
• Resources
• Build GUI with XML
• Toast
4
Android Schematics
5
Task (UI Application)
• Runs in one process
– usually!
– There are exceptions
• Stack of activities
• Root activity
– Add
• Display
• push
– Remove
• Hide
• pop
– Activities from other
applications
6
Task (UI Application)
• Runs in one process
– usually!
– There are exceptions
• Stack of activities
• Root activity
– Add
• Display
• push
– Remove
• Hide
• pop
– Activities from other
applications
7
Manifest
AndroidManifest.xml
– Declare components (Activities, Services, etc)
– Declare permissions
8
Context
• Context
– Any application
component
• Activities
• Services
• Content Providers
• Broadcast Receivers
– Generated by Dalvik/ART
• At startup
• Provided as a parameter
9
Context
• Abstract Class
– Extended by
• Activity
• Service
• ContentProvider
• …
• Advantages
– Avoids static class
• Disadvantage
– Has to be provided as
parameter
10
Activity
• One Window
– Uses all the screen
(usually)
• Contains
– Title
– One component
– One menu
• Activated by the menu
(soft) button
• Extends Activity
11
Activity Life Cycle
12
Important Functions
• Clasa Activity
– void onCreate (…);
– void onStart (…);
– void onRestart (…);
– void onResume (…);
– void onPause (…);
– void onStop (…);
– void onDestroy (…);
• Must call the parent
overridden functions
• super.onCreate (…);
– …
13
Acitivity
• Window
• Survives the process
– Serialising
– Partially controlled by
the programmer
• Not for heavy
processing
14
Storing and loading of the status
• Store
– void onSaveInstanceState (Bundle state)
• Load
– void onLoadInstanceState (Bundle state)
– void onCreate (Bundle savedInstance)
15
Starting of an activity
• context.startActivity (Intent intent);
Intent starter = new Intent (context,
ActivityClass.class);
context.startActivity (starter);
16
Stopping an activity
• context.finishActivity (Intent intent);
– Another component wants to stop the Activity
• finish ();
– The Activity stops itself
Intent starter = new Intent (context,
ActivityClass.class);
Context.finishActivity (starter);
17
Components (Widgets)
• Extend View
• Placed on an Activity
– Static
• TextView
• ProgressBar
• ImageView
• …
– Dynamic
• Button
• EditText
• CheckBox
• RadioButton
• SeekBar
• Spinner
• Gallery
• MapView
• ListView
• …
18
Components (Docs)
19
Program (Docs)
20
Container
• View
– Contains other Views
– Layout
• Types
– LinearLayout
– RelativeLayout
– TableLayout
– ScrollLayout
• They are used
combined
21
Container Types
LinearLayout RelativeLayout
22
Container Types
TableLayout AbsoluteLayout
23
Resources
• res folder (from the source)
• Images
– drawable -_dpi
• ldpi
• mdpi
• hdpi
• UI
– layout
• Constants
– Values
• strings.xml
• Raw
– Unmodifiable resources
24
Automatic resources in Java code
• Drawable
– Images
– R.drawable.name
• R.drawable.icon
• R.drawable.img1
• R.drawable.img2
• Layout
– Containers
– R.layout.name
• R.layout.main
• R.layout.people
25
Automatic resources in XML
• Drawable
– Images
– @drawable/name
• @drawable/icon
• @drawable/img1
• @drawable/img2
• Layout
– Containers
– @layout/name
• @layout/main
• @layout/people
26
Constructing the GUI with XML
• Complex component
• Simple code
• No Java code
• In the Activity code
– this.setContentView (R.layout.name);
27
GUI XML example file
28
GUI XML example file
• xmlns:android
– Only the root component
– mandatory
• android:layout_width
• android:layout_height
– mandatory
– Values
• fill_parent
• wrap_content
• match_parent
• n px
• n cm
29
GUI XML example file
• android:id
– Usage of the component
in the Java code
– @+id/name
• R.id.name
– Example
• @+id/button1
– R.id.button1
30
GUI XML example file
• android:id
– Usage of the component
in the Java code
– @+id/name
• R.id.name
– Example
• @+id/button1
– R.id.button1
31
GUI XML example file
XML Java Code
32
Menu
• MENU (soft) button press
• Events
– public boolean
onCreateOptionsMenu (Menu
menu);
– public boolean
onOptionsItemSelected(MenuItem
item);
• Adding a menu
– menu.add (…);
33
Menu Example
34
Menu using XML
XML (res/menu/meniu.xml) Java Code
35
Menu using XML
• XML (res/menu/meniu.xml)
36
Menu using XML
• Java Code
37
Toast
• Display notifications
– Short
• Toast.LENGTH_SHORT
– Long
• Toast.LENGTH_LONG
• Toast
38
Conclusions
• Task
– A stack of activities
• Manifest
– Declare activities
• Activities
– Android Windows
– Survive the process
– Displays one single component
• Use containers
– LinearLayout, RelativeLayout, TableLayout
• Automatic Resources
– Drawable
• R.drawable.nume
• @/drawable/nume
– Layout
• Fișiere XML
• R.layout.nume
• @/layout/nume
• Toast
– Display messages
39
Keywords
• Task
– Stack
• Activity
– Lifecycle
• Containers
– Layouts
– LinearLayout
– TableLayout
– RelativeLayout
– GridLayout
• Toast
• XML GUI
• Menu
• Manifest
• Components
– Static
• TextView
• ProgressBar
• ImageView
• …
– Dynamic
• Button
• EditText
• CheckBox
• RadioButton
• SeekBar
• Spinner
• Gallery
• MapView
• ListView
40
Quenstions
41

More Related Content

Similar to MDAD 4 - Android - Basics of UI Applications

Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android DevelopmentJussi Pohjolainen
 
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012Tomáš Kypta
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Android studio
Android studioAndroid studio
Android studioAndri Yabu
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controlsDaniel Fisher
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycleSokngim Sa
 
Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013Tomáš Kypta
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen Chen
 
Dori waldman android _course
Dori waldman android _courseDori waldman android _course
Dori waldman android _courseDori Waldman
 
Advanced android app lifecycle + Patterns
Advanced android app lifecycle + PatternsAdvanced android app lifecycle + Patterns
Advanced android app lifecycle + Patternsbryan costanich
 
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 application development
Android application developmentAndroid application development
Android application developmentslidesuren
 

Similar to MDAD 4 - Android - Basics of UI Applications (20)

Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android - Android Application Configuration
Android - Android Application ConfigurationAndroid - Android Application Configuration
Android - Android Application Configuration
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
Opensocial
OpensocialOpensocial
Opensocial
 
Android Lab
Android LabAndroid Lab
Android Lab
 
Android studio
Android studioAndroid studio
Android studio
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycle
 
Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Dori waldman android _course
Dori waldman android _courseDori waldman android _course
Dori waldman android _course
 
Unit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.pptUnit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.ppt
 
Advanced android app lifecycle + Patterns
Advanced android app lifecycle + PatternsAdvanced android app lifecycle + Patterns
Advanced android app lifecycle + Patterns
 
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 application development
Android application developmentAndroid application development
Android application development
 

More from Alexandru Radovici (20)

SdE2 - Pilot Tock
SdE2 - Pilot TockSdE2 - Pilot Tock
SdE2 - Pilot Tock
 
SdE2 - Systèmes embarquées
SdE2 - Systèmes embarquéesSdE2 - Systèmes embarquées
SdE2 - Systèmes embarquées
 
SdE2 - Planification, IPC
SdE2 - Planification, IPCSdE2 - Planification, IPC
SdE2 - Planification, IPC
 
ALF1 - Introduction
ALF1 - IntroductionALF1 - Introduction
ALF1 - Introduction
 
SdE2 - Introduction
SdE2 - IntroductionSdE2 - Introduction
SdE2 - Introduction
 
MDAD 6 - AIDL and Services
MDAD 6 - AIDL and ServicesMDAD 6 - AIDL and Services
MDAD 6 - AIDL and Services
 
MDAD 5 - Threads
MDAD 5 - ThreadsMDAD 5 - Threads
MDAD 5 - Threads
 
MDAD 1 - Hardware
MDAD 1 - HardwareMDAD 1 - Hardware
MDAD 1 - Hardware
 
MDAD 0 - Introduction
MDAD 0 - IntroductionMDAD 0 - Introduction
MDAD 0 - Introduction
 
SdE 11 - Reseau
SdE 11 - ReseauSdE 11 - Reseau
SdE 11 - Reseau
 
SdE 10 - Threads
SdE 10 - ThreadsSdE 10 - Threads
SdE 10 - Threads
 
SdE 8 - Synchronisation de execution
SdE 8 - Synchronisation de executionSdE 8 - Synchronisation de execution
SdE 8 - Synchronisation de execution
 
SdE 8 - Memoire Virtuelle
SdE 8 - Memoire VirtuelleSdE 8 - Memoire Virtuelle
SdE 8 - Memoire Virtuelle
 
SdE 7 - Gestion de la Mémoire
SdE 7 - Gestion de la MémoireSdE 7 - Gestion de la Mémoire
SdE 7 - Gestion de la Mémoire
 
SdE 6 - Planification
SdE 6 - PlanificationSdE 6 - Planification
SdE 6 - Planification
 
SdE 5 - Planification
SdE 5 - PlanificationSdE 5 - Planification
SdE 5 - Planification
 
ALF 6 - Parser
ALF 6 - ParserALF 6 - Parser
ALF 6 - Parser
 
ALF 5 - Parser
ALF 5 - ParserALF 5 - Parser
ALF 5 - Parser
 
ALF 4 - Grammaires
ALF 4 - GrammairesALF 4 - Grammaires
ALF 4 - Grammaires
 
ALF 3 - Expressions régulières et Lexer
ALF 3 - Expressions régulières et LexerALF 3 - Expressions régulières et Lexer
ALF 3 - Expressions régulières et Lexer
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

MDAD 4 - Android - Basics of UI Applications

  • 1. Android Basics of UI Applications
  • 2. Bibliography 1. Wallace Jackson, Android Apps for Absolute Beginners, Apress, 2017 2. Peter Späth, Learn Kotlin for Android Development, Apress 2019 3. Android Application Fundamentals, http://developer.android.com/guide/topics/f undamentals.html 2
  • 3. Let’s recap • Android – OS – Platform – Kernel – User space libraries – Dalvik / ART – Android Libraries – Applications • Android Applications – Types – Security 3
  • 4. Contents • Task • Manifest • Context • Activity – Life cycle – Activity types – Components • Containers • Resources • Build GUI with XML • Toast 4
  • 6. Task (UI Application) • Runs in one process – usually! – There are exceptions • Stack of activities • Root activity – Add • Display • push – Remove • Hide • pop – Activities from other applications 6
  • 7. Task (UI Application) • Runs in one process – usually! – There are exceptions • Stack of activities • Root activity – Add • Display • push – Remove • Hide • pop – Activities from other applications 7
  • 8. Manifest AndroidManifest.xml – Declare components (Activities, Services, etc) – Declare permissions 8
  • 9. Context • Context – Any application component • Activities • Services • Content Providers • Broadcast Receivers – Generated by Dalvik/ART • At startup • Provided as a parameter 9
  • 10. Context • Abstract Class – Extended by • Activity • Service • ContentProvider • … • Advantages – Avoids static class • Disadvantage – Has to be provided as parameter 10
  • 11. Activity • One Window – Uses all the screen (usually) • Contains – Title – One component – One menu • Activated by the menu (soft) button • Extends Activity 11
  • 13. Important Functions • Clasa Activity – void onCreate (…); – void onStart (…); – void onRestart (…); – void onResume (…); – void onPause (…); – void onStop (…); – void onDestroy (…); • Must call the parent overridden functions • super.onCreate (…); – … 13
  • 14. Acitivity • Window • Survives the process – Serialising – Partially controlled by the programmer • Not for heavy processing 14
  • 15. Storing and loading of the status • Store – void onSaveInstanceState (Bundle state) • Load – void onLoadInstanceState (Bundle state) – void onCreate (Bundle savedInstance) 15
  • 16. Starting of an activity • context.startActivity (Intent intent); Intent starter = new Intent (context, ActivityClass.class); context.startActivity (starter); 16
  • 17. Stopping an activity • context.finishActivity (Intent intent); – Another component wants to stop the Activity • finish (); – The Activity stops itself Intent starter = new Intent (context, ActivityClass.class); Context.finishActivity (starter); 17
  • 18. Components (Widgets) • Extend View • Placed on an Activity – Static • TextView • ProgressBar • ImageView • … – Dynamic • Button • EditText • CheckBox • RadioButton • SeekBar • Spinner • Gallery • MapView • ListView • … 18
  • 21. Container • View – Contains other Views – Layout • Types – LinearLayout – RelativeLayout – TableLayout – ScrollLayout • They are used combined 21
  • 24. Resources • res folder (from the source) • Images – drawable -_dpi • ldpi • mdpi • hdpi • UI – layout • Constants – Values • strings.xml • Raw – Unmodifiable resources 24
  • 25. Automatic resources in Java code • Drawable – Images – R.drawable.name • R.drawable.icon • R.drawable.img1 • R.drawable.img2 • Layout – Containers – R.layout.name • R.layout.main • R.layout.people 25
  • 26. Automatic resources in XML • Drawable – Images – @drawable/name • @drawable/icon • @drawable/img1 • @drawable/img2 • Layout – Containers – @layout/name • @layout/main • @layout/people 26
  • 27. Constructing the GUI with XML • Complex component • Simple code • No Java code • In the Activity code – this.setContentView (R.layout.name); 27
  • 28. GUI XML example file 28
  • 29. GUI XML example file • xmlns:android – Only the root component – mandatory • android:layout_width • android:layout_height – mandatory – Values • fill_parent • wrap_content • match_parent • n px • n cm 29
  • 30. GUI XML example file • android:id – Usage of the component in the Java code – @+id/name • R.id.name – Example • @+id/button1 – R.id.button1 30
  • 31. GUI XML example file • android:id – Usage of the component in the Java code – @+id/name • R.id.name – Example • @+id/button1 – R.id.button1 31
  • 32. GUI XML example file XML Java Code 32
  • 33. Menu • MENU (soft) button press • Events – public boolean onCreateOptionsMenu (Menu menu); – public boolean onOptionsItemSelected(MenuItem item); • Adding a menu – menu.add (…); 33
  • 35. Menu using XML XML (res/menu/meniu.xml) Java Code 35
  • 36. Menu using XML • XML (res/menu/meniu.xml) 36
  • 37. Menu using XML • Java Code 37
  • 38. Toast • Display notifications – Short • Toast.LENGTH_SHORT – Long • Toast.LENGTH_LONG • Toast 38
  • 39. Conclusions • Task – A stack of activities • Manifest – Declare activities • Activities – Android Windows – Survive the process – Displays one single component • Use containers – LinearLayout, RelativeLayout, TableLayout • Automatic Resources – Drawable • R.drawable.nume • @/drawable/nume – Layout • Fișiere XML • R.layout.nume • @/layout/nume • Toast – Display messages 39
  • 40. Keywords • Task – Stack • Activity – Lifecycle • Containers – Layouts – LinearLayout – TableLayout – RelativeLayout – GridLayout • Toast • XML GUI • Menu • Manifest • Components – Static • TextView • ProgressBar • ImageView • … – Dynamic • Button • EditText • CheckBox • RadioButton • SeekBar • Spinner • Gallery • MapView • ListView 40