SlideShare una empresa de Scribd logo
1 de 33
Android Programming
Basic
Agenda
Introducing Android
•   What is android?
•   Android architecture
•   Installing the tools
•   Creating first program
Android basic
•   Layout
•   Custom component
•   Menu
•   Dialog
•   Supporting Multiple Screens
•   Activity
•   Google map
•   Location services
•   Using sensors
•   Communicating with the server
•   Working in the background
Introducing android
What is android?
Android is a Linux-based mobile phone operating system developed
by Google

•Open

•All application are created equal

•Breaking down application boundaries

•Fast & easy application development
What is android?




                   Source: An introduction to android – Huang Xuguang
What is android?
U.S. Smartphone Market share
Android architecture




                       Source: http://developer.android.com
Installing the tools
Java SE (JDK)

Eclipse

Android SDK

Android Development Tools (ADT) for Eclipse

Android platforms and other components

Create virtual device
Creating first program
Android basic
Layout

• Linear Layout

• Frame Layout

• Absolute Layout

• Relative Layout

• Table Layout
Custom Component
Extend an existing View class

Override some of the methods from the superclass
•   onDraw: Called when the view should render its content.

•   onMeasure: Called to determine the size requirements for this view and all of its
    children.

•   onTouchEvent, onKeyUp, onKeyDown …
Custom component
Use the Custom Component
Menu

• Options Menu: The primary collection of menu items for an activity,
  which appears when the user touches the MENU button.

• Context Menu: A floating list of menu items that appears when the
  user touches and holds a view that's registered to provide a context
  menu.

• Sub Menu: A floating list of menu items that appears when the user
  touches a menu item that contains a nested menu.
Dialog




• Alert Dialog

• Progress Dialog

• Date Picker Dialog

• Time Picker Dialog

• Custom Dialog


                       Source: http://developer.android.com
Supporting Multiple Screens
Display units in android
• dp: Density-independent Pixels - an abstract unit that is based on the physical
   density of the screen. These units are relative to a 160 dpi (dots per inch)
   screen, so 160dp is always one inch regardless of the screen density
   The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For
   example, on a 160 dpi screen, 1 dp equals 1 physical pixels and on a 240 dpi
   screen, 1 dp equals 1.5 physical pixels…

• sp: Scale-independent Pixels - this is like the dp unit, but it is also scaled by the
   user's font size preference.

• pt: Points - 1/72 of an inch based on the physical size of the screen

• px: Pixels - corresponds to actual pixels on the screen

• mm: Millimeters - based on the physical size of the screen.

• in: Inches - based on the physical size of the screen.

                                                                      Source: http://developer.android.com
Supporting Multiple Screens
 Density independence




Example application without support for different densities, as shown on low, medium, and high density screens.




Example application with good support for different densities (it's density independent), as shown on low, medium, and high density
screens.




                                                                                                   Source: http://developer.android.com
Supporting Multiple Screens
Using configuration qualifiers
•   Directory qualifier
    Size:         small, normal, large, xlarge
    Density:       ldpi (~120dpi), mdpi (~160dpi), hdpi (~240dpi), xhdpi, nodpi, tvdpi
    Aspect ratio: long, notlong
    Orientation: land, port

•   List of resource directory




•   Specific screen size (via the AndroidManifest)




                                                                                         Source: http://developer.android.com
Supporting Multiple Screens
NinePatch




              Source: http://www.developer.com/ws/other/article.php/3889086/Working-
                                  with-NinePatch-Stretchable-Graphics-in-Android.htm
Supporting Multiple Screens
Draw 9-patch




               Source: http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial
Activity
•   An Activity roughly corresponds to screen

•   They appear on a stack, with one visible at a time, and use a BACK button for
    reverse navigation through the stack
Activity
Activity Lifecycle
Activity
Navigating to another activity




Wait for result
Activity
Passing data to another activity




Sharing data among activities
• using a class with a lot of static variables
• File or database
Google map
Location services
Cell ID
•   Each cell tower worldwide has a unique identifier called Cell ID
•   Each tower knows its latitude and longitude, so it's easy enough for a mobile phone
    to know "approximately" where you are located


Triangulation
•   Most of the time your mobile phone is in range of more
    than one cell tower
•   The cell tower has the ability to tell what direction your
    signal is coming from
•   If there are two or three towers that can see your
    phone, together they can triangulate on your phone's
    location

GPS
• The satellite-based Global Positioning System (GPS)
• Your mobile phone can determine its location very accurately




                                                 Source: http://www.helloandroid.com/content/location-and-mapping
Using sensors
Android supports several sensors via the SensorManager
•   Accelerometer
•   Compass
•   Temperature
•   Gyroscope
•   Gravity
•   Proximity
•   …

Can not test on the Android emulator
Communicating with the server

• HttpGet

• HttpPost

• Socket

• Call webservice using ksoap2
Working in the background
Threads
•   Android supports standart Java Threads.

•   If you need update the UI in a separate thread you need to use Handler
    (android.os.Handler). When you send message to the Handler and it will get
    saved into a queue and get executed by the UI thread as soon as possible.



Handler
•   The class "Handler" can update the UI.
Working in the background
AsyncTask
•   The class AsyncTask encapsulates the creation of Threads and Handlers

•   AsyncTask enables proper and easy use of the UI thread

•   An asynchronous task is defined by 3 generic types, called Params, Progress and
    Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and
    onPostExecute.

•   Example:
References
•   Thesis - Android programming – Vo Thanh Nhat & Phan Thanh Trung –
    University of Science Ho Chi Minh City

•   Hello android – Introducing Google Mobile’s Development Platform – Ed
    Burnette

•   Wrox – Professional Android Application development – Rito Meier

•   Wrox – Professional Android 2 Application development – Rito Meier

•   Apress – Pro Android – Sayed Y.Hashimi and Satya Komatineni

•   http://developer.android.com

•   http://stackoverflow.com

•   http://www.helloandroid.com

•   …
Slide, tools, documents &
samples
Share on my PC now: yp-tienhungandroid
Q&A

Más contenido relacionado

La actualidad más candente

Android terminologies
Android terminologiesAndroid terminologies
Android terminologiesjerry vasoya
 
Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1Kainda Kiniel Daka
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development WorkshopPeter Robinett
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentCan Elmas
 
Android architecture
Android architectureAndroid architecture
Android architectureHari Krishna
 
Introduction to Android, Architecture & Components
Introduction to  Android, Architecture & ComponentsIntroduction to  Android, Architecture & Components
Introduction to Android, Architecture & ComponentsVijay Rastogi
 
Java Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopJava Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopKasun Dananjaya Delgolla
 
Android application development ppt
Android application development pptAndroid application development ppt
Android application development pptGautam Kumar
 
Android Introduction 2013
Android Introduction 2013Android Introduction 2013
Android Introduction 2013Bhavya Siddappa
 
Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA NITIN GUPTA
 

La actualidad más candente (20)

Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development Workshop
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android workShop
Android workShopAndroid workShop
Android workShop
 
Android basics
Android basicsAndroid basics
Android basics
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Introduction to Android, Architecture & Components
Introduction to  Android, Architecture & ComponentsIntroduction to  Android, Architecture & Components
Introduction to Android, Architecture & Components
 
Android Training
Android TrainingAndroid Training
Android Training
 
Android
AndroidAndroid
Android
 
Java Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopJava Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development Workshop
 
Android application development ppt
Android application development pptAndroid application development ppt
Android application development ppt
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android PPT
Android PPTAndroid PPT
Android PPT
 
Android Presentation
Android PresentationAndroid Presentation
Android Presentation
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android Introduction 2013
Android Introduction 2013Android Introduction 2013
Android Introduction 2013
 
Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA
 

Destacado

Android Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADTAndroid Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADTEakapong Kattiya
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android StudioMichael Pan
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The BasicsMike Desjardins
 
My presentation on Android in my college
My presentation on Android in my collegeMy presentation on Android in my college
My presentation on Android in my collegeSneha Lata
 

Destacado (8)

Android Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADTAndroid Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADT
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android Studio
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The Basics
 
My presentation on Android in my college
My presentation on Android in my collegeMy presentation on Android in my college
My presentation on Android in my college
 
Android seminar ppt
Android seminar pptAndroid seminar ppt
Android seminar ppt
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android ppt
Android ppt Android ppt
Android ppt
 

Similar a Android Programming Basic

Android webinar class_1
Android webinar class_1Android webinar class_1
Android webinar class_1Edureka!
 
Introduction to Android (before 2015)
Introduction to Android (before 2015)Introduction to Android (before 2015)
Introduction to Android (before 2015)Chien-Ming Chou
 
Learn Android at edureka!
Learn Android at edureka! Learn Android at edureka!
Learn Android at edureka! Edureka!
 
Beating Android Fragmentation, Brett Duncavage
Beating Android Fragmentation, Brett DuncavageBeating Android Fragmentation, Brett Duncavage
Beating Android Fragmentation, Brett DuncavageXamarin
 
Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1drudolph11
 
Android development workshop
Android development workshopAndroid development workshop
Android development workshopJeff Sonstein
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introductionsaivvit
 
Android development orientation for starters v2
Android development orientation for starters v2Android development orientation for starters v2
Android development orientation for starters v2Joemarie Amparo
 
Android Development recipes with java.pptx
Android Development recipes with java.pptxAndroid Development recipes with java.pptx
Android Development recipes with java.pptxabdulqayoomjat2470
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1Purvik Rana
 
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
 
Angular mobile angular_u
Angular mobile angular_uAngular mobile angular_u
Angular mobile angular_uDoris Chen
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 

Similar a Android Programming Basic (20)

Android webinar class_1
Android webinar class_1Android webinar class_1
Android webinar class_1
 
Introduction to Android (before 2015)
Introduction to Android (before 2015)Introduction to Android (before 2015)
Introduction to Android (before 2015)
 
Learn Android at edureka!
Learn Android at edureka! Learn Android at edureka!
Learn Android at edureka!
 
Beating Android Fragmentation, Brett Duncavage
Beating Android Fragmentation, Brett DuncavageBeating Android Fragmentation, Brett Duncavage
Beating Android Fragmentation, Brett Duncavage
 
Android development first steps
Android development   first stepsAndroid development   first steps
Android development first steps
 
Android
Android Android
Android
 
Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1
 
Android OS
Android OSAndroid OS
Android OS
 
Android development workshop
Android development workshopAndroid development workshop
Android development workshop
 
Android quick talk
Android quick talkAndroid quick talk
Android quick talk
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Android Presentation
Android PresentationAndroid Presentation
Android Presentation
 
Intro to android (gdays)
Intro to android (gdays)Intro to android (gdays)
Intro to android (gdays)
 
Android development orientation for starters v2
Android development orientation for starters v2Android development orientation for starters v2
Android development orientation for starters v2
 
Android Development recipes with java.pptx
Android Development recipes with java.pptxAndroid Development recipes with java.pptx
Android Development recipes with java.pptx
 
UI and UX for Mobile Developers
UI and UX for Mobile DevelopersUI and UX for Mobile Developers
UI and UX for Mobile Developers
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1
 
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
 
Angular mobile angular_u
Angular mobile angular_uAngular mobile angular_u
Angular mobile angular_u
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 

Más de Duy Do Phan

Más de Duy Do Phan (13)

Twitter Bootstrap Presentation
Twitter Bootstrap PresentationTwitter Bootstrap Presentation
Twitter Bootstrap Presentation
 
BlackBerry Basic
BlackBerry BasicBlackBerry Basic
BlackBerry Basic
 
PCI DSS
PCI DSSPCI DSS
PCI DSS
 
WCF
WCFWCF
WCF
 
Location based AR & how it works
Location based AR & how it worksLocation based AR & how it works
Location based AR & how it works
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
 
Iso8583
Iso8583Iso8583
Iso8583
 
Cryptography Fundamentals
Cryptography FundamentalsCryptography Fundamentals
Cryptography Fundamentals
 
SSL
SSLSSL
SSL
 
iOS Basic
iOS BasiciOS Basic
iOS Basic
 
SMS-SMPP-Concepts
SMS-SMPP-ConceptsSMS-SMPP-Concepts
SMS-SMPP-Concepts
 
One minute manager
One minute managerOne minute manager
One minute manager
 
Work life balance
Work life balanceWork life balance
Work life balance
 

Android Programming Basic

  • 2. Agenda Introducing Android • What is android? • Android architecture • Installing the tools • Creating first program Android basic • Layout • Custom component • Menu • Dialog • Supporting Multiple Screens • Activity • Google map • Location services • Using sensors • Communicating with the server • Working in the background
  • 4. What is android? Android is a Linux-based mobile phone operating system developed by Google •Open •All application are created equal •Breaking down application boundaries •Fast & easy application development
  • 5. What is android? Source: An introduction to android – Huang Xuguang
  • 6. What is android? U.S. Smartphone Market share
  • 7. Android architecture Source: http://developer.android.com
  • 8. Installing the tools Java SE (JDK) Eclipse Android SDK Android Development Tools (ADT) for Eclipse Android platforms and other components Create virtual device
  • 11. Layout • Linear Layout • Frame Layout • Absolute Layout • Relative Layout • Table Layout
  • 12. Custom Component Extend an existing View class Override some of the methods from the superclass • onDraw: Called when the view should render its content. • onMeasure: Called to determine the size requirements for this view and all of its children. • onTouchEvent, onKeyUp, onKeyDown …
  • 13. Custom component Use the Custom Component
  • 14. Menu • Options Menu: The primary collection of menu items for an activity, which appears when the user touches the MENU button. • Context Menu: A floating list of menu items that appears when the user touches and holds a view that's registered to provide a context menu. • Sub Menu: A floating list of menu items that appears when the user touches a menu item that contains a nested menu.
  • 15. Dialog • Alert Dialog • Progress Dialog • Date Picker Dialog • Time Picker Dialog • Custom Dialog Source: http://developer.android.com
  • 16. Supporting Multiple Screens Display units in android • dp: Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, so 160dp is always one inch regardless of the screen density The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 160 dpi screen, 1 dp equals 1 physical pixels and on a 240 dpi screen, 1 dp equals 1.5 physical pixels… • sp: Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. • pt: Points - 1/72 of an inch based on the physical size of the screen • px: Pixels - corresponds to actual pixels on the screen • mm: Millimeters - based on the physical size of the screen. • in: Inches - based on the physical size of the screen. Source: http://developer.android.com
  • 17. Supporting Multiple Screens Density independence Example application without support for different densities, as shown on low, medium, and high density screens. Example application with good support for different densities (it's density independent), as shown on low, medium, and high density screens. Source: http://developer.android.com
  • 18. Supporting Multiple Screens Using configuration qualifiers • Directory qualifier Size: small, normal, large, xlarge Density: ldpi (~120dpi), mdpi (~160dpi), hdpi (~240dpi), xhdpi, nodpi, tvdpi Aspect ratio: long, notlong Orientation: land, port • List of resource directory • Specific screen size (via the AndroidManifest) Source: http://developer.android.com
  • 19. Supporting Multiple Screens NinePatch Source: http://www.developer.com/ws/other/article.php/3889086/Working- with-NinePatch-Stretchable-Graphics-in-Android.htm
  • 20. Supporting Multiple Screens Draw 9-patch Source: http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial
  • 21. Activity • An Activity roughly corresponds to screen • They appear on a stack, with one visible at a time, and use a BACK button for reverse navigation through the stack
  • 23. Activity Navigating to another activity Wait for result
  • 24. Activity Passing data to another activity Sharing data among activities • using a class with a lot of static variables • File or database
  • 26. Location services Cell ID • Each cell tower worldwide has a unique identifier called Cell ID • Each tower knows its latitude and longitude, so it's easy enough for a mobile phone to know "approximately" where you are located Triangulation • Most of the time your mobile phone is in range of more than one cell tower • The cell tower has the ability to tell what direction your signal is coming from • If there are two or three towers that can see your phone, together they can triangulate on your phone's location GPS • The satellite-based Global Positioning System (GPS) • Your mobile phone can determine its location very accurately Source: http://www.helloandroid.com/content/location-and-mapping
  • 27. Using sensors Android supports several sensors via the SensorManager • Accelerometer • Compass • Temperature • Gyroscope • Gravity • Proximity • … Can not test on the Android emulator
  • 28. Communicating with the server • HttpGet • HttpPost • Socket • Call webservice using ksoap2
  • 29. Working in the background Threads • Android supports standart Java Threads. • If you need update the UI in a separate thread you need to use Handler (android.os.Handler). When you send message to the Handler and it will get saved into a queue and get executed by the UI thread as soon as possible. Handler • The class "Handler" can update the UI.
  • 30. Working in the background AsyncTask • The class AsyncTask encapsulates the creation of Threads and Handlers • AsyncTask enables proper and easy use of the UI thread • An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute. • Example:
  • 31. References • Thesis - Android programming – Vo Thanh Nhat & Phan Thanh Trung – University of Science Ho Chi Minh City • Hello android – Introducing Google Mobile’s Development Platform – Ed Burnette • Wrox – Professional Android Application development – Rito Meier • Wrox – Professional Android 2 Application development – Rito Meier • Apress – Pro Android – Sayed Y.Hashimi and Satya Komatineni • http://developer.android.com • http://stackoverflow.com • http://www.helloandroid.com • …
  • 32. Slide, tools, documents & samples Share on my PC now: yp-tienhungandroid
  • 33. Q&A

Notas del editor

  1. Section divider 1
  2. Slide text 2
  3. Slide text 2
  4. Slide text 2
  5. Slide text 2
  6. Slide text 2
  7. Slide text 2
  8. Slide text 2
  9. Slide text 2
  10. Slide text 2
  11. Slide text 2
  12. Slide text 2
  13. Slide text 2
  14. Slide text 2
  15. Slide text 2
  16. Slide text 2
  17. Slide text 2
  18. Slide text 2
  19. Slide text 2
  20. Slide text 2
  21. Slide text 2
  22. Slide text 2
  23. Slide text 2
  24. Slide text 2
  25. Slide text 2
  26. Slide text 2
  27. Slide text 2
  28. Slide text 2
  29. Section divider 1