INTRODUCTION TO
ANDROID
STEFAN BLOS
AGENDA
▸ Facts about Android
▸ Basic Building Blocks of Apps
▸ HelloAndroid-App
WHO IS THAT GUY?
▸ CS student with focus on Machine Learning & AI
▸ Freelance app developer
▸ Recipient of Google scholarship to learn Android at Udacity
FACTS
ABOUT
ANDROID
How many active Android devices?
2 billion
Market Share in Mobile OS
87.7 %
Number of Apps in Google Play
> 2 million
LARGE COMMUNITY
▸ Developers
▸ Open-Source projects
▸ Libraries
ANDROID SYSTEM
ANDROID SYSTEM
▸ Linux kernel
▸ Applications are abstracted from that - no need to worry about
lower layers
▸ Apps use Gradle as a build system
▸ Java & Kotlin as official languages for developing Apps
BASIC
BUILDING
BLOCKS
BUILDING BLOCKS
▸ Activities
▸ Services
▸ BroadcastReceivers
▸ ContentProviders
ACTIVITIES
▸ An Activity is the screen that the user sees
▸ Basis of user interaction
▸ They have a „lifecycle“
▸ Fragments are tiny Activities with own purpose
SERVICES
▸ Some tasks require to run in background
▸ AsyncTask is able to run when app is active
▸ Services can run even when the App is not opened
WHEN TO USE A SERVICE?
▸ Rule of thumb to distinguish between AsyncTask and
Services:
▸ AsyncTask —> quick (< 1 second), inside the app

(e.g. download user avatar, update UI from background)
▸ Service —> longer (> 1 second), also when app closes

(e.g. download mp3 in background)
BROADCAST RECEIVERS
▸ Broadcast = message sent when „events of interest“ occur
▸ Can be inside of your app or between Apps
▸ Can also be sent by the system (e.g. incoming phone call)
▸ You can either publish or subscribe to Broadcasts
CONTENT PROVIDER
▸ Best practice to store data
▸ Makes it possible to share data between apps
▸ provides an interface to easily manage different kinds of
data

(SQLite databases, video, audio, etc.)
ACTIVITIES
WHAT DOES IT DO?
▸ What the user sees and interacts with
▸ Shows information to your user
▸ Responds to input from your user
WHAT ARE ACTIVITIES MADE OFF?
▸ Java (or Kotlin) file for the logic and interaction
▸ Interface (.xml) file for defining what the user sees
WHAT ARE ACTIVITIES MADE OFF?
▸ Java (or Kotlin) file for the logic and interaction
▸ Interface (.xml) file for defining what the user sees
JAVA PART OF ACTIVITY
▸ Indicates which user interface is used
▸ Manages user input
▸ Responds to the activity lifecycle
ACTIVITY
LIFECYCLE
LIFECYCLE LITE
▸ System tells you the state of your activity
▸ When app is started —> Activity created

onCreate()
▸ When it is shown on screen —> Activity started

onStart()
LIFECYCLE LITE (CONT’D)
▸ When no longer in foreground —> Activity paused (and
resumed)

onPause() —> onResume()
▸ When no longer visible —> Activity stopped (and restarted)

onStop() —> onRestart()
▸ When it is shut down —> Activity destroyed

onDestroy()
WHAT ARE ACTIVITIES MADE OFF?
▸ Java (or Kotlin) file for the logic and interaction
▸ Interface (.xml) file for defining what the user sees
INTERFACE PART OF ACTIVITY
▸ Layout file format is .xml
▸ offers a visual editor
▸ creates the layout of the screen with building blocks
▸ showing text —> TextView
▸ show image —> ImageView
▸ let the user input text —> EditText
▸ ordering of blocks is done via layouts
TextView
ImageView
EditText
HOW TO BUILD AN INTERFACE?
▸ All building blocks are Views
▸ Views have properties like:
▸ id
▸ width
▸ height
HOW TO MANAGE ALL THOSE VIEWS?
▸ Views are bundled together in ViewGroups

(fun fact: these are groups of views)
▸ Layout types define the order of elements in ViewGroups
COMMON LAYOUTS
▸ LinearLayout
▸ RelativeLayout
▸ ConstraintLayout
COMMON LAYOUTS (CONT’D)
▸ Different kinds of List layouts
▸ RecyclerViews (not a real layout but important)
▸ ListView
▸ GridView
HOW CAN WE START OTHER ACTIVITIES?
▸ Intents are used (can be thought of like envelopes)
▸ On creation of intent specify Activity (here „ActivityB“) to
start and then start it:
WE CAN ALSO PASS DATA WITH INTENTS
▸ Data is put into Intent with an id by Activity A:
▸ Can be accessed with id by Activity B:
Activity A
Activity B
Data
id
id
HELLO
ANDROID
APP
WHAT TOOLS ARE WE USING?
▸ We use the Android SDK
▸ We use Android Studio
▸ Generates .apk (Android Package) which can be installed on
device
Live-Coding
SOME
USEFUL
RESSOURCES
▸ Android Developer Portal:



https://developer.android.com/
▸ Android Trainings in the Developer Portal:



https://developer.android.com/training/basics/firstapp/
index.html
▸ Slides for Beginners (also from Google):



https://drive.google.com/drive/u/0/folders/
0B5Kg0X0yIQ1Pbk5yVGdsSFFjR28
▸ Free courses on Udacity:



https://de.udacity.com/courses/android
Thanks!
On to the Codelabs…

Android Introduction Talk

  • 1.
  • 2.
    AGENDA ▸ Facts aboutAndroid ▸ Basic Building Blocks of Apps ▸ HelloAndroid-App
  • 3.
    WHO IS THATGUY? ▸ CS student with focus on Machine Learning & AI ▸ Freelance app developer ▸ Recipient of Google scholarship to learn Android at Udacity
  • 4.
  • 5.
    How many activeAndroid devices? 2 billion
  • 6.
    Market Share inMobile OS 87.7 %
  • 7.
    Number of Appsin Google Play > 2 million
  • 9.
    LARGE COMMUNITY ▸ Developers ▸Open-Source projects ▸ Libraries
  • 10.
  • 11.
    ANDROID SYSTEM ▸ Linuxkernel ▸ Applications are abstracted from that - no need to worry about lower layers ▸ Apps use Gradle as a build system ▸ Java & Kotlin as official languages for developing Apps
  • 13.
  • 14.
    BUILDING BLOCKS ▸ Activities ▸Services ▸ BroadcastReceivers ▸ ContentProviders
  • 15.
    ACTIVITIES ▸ An Activityis the screen that the user sees ▸ Basis of user interaction ▸ They have a „lifecycle“ ▸ Fragments are tiny Activities with own purpose
  • 16.
    SERVICES ▸ Some tasksrequire to run in background ▸ AsyncTask is able to run when app is active ▸ Services can run even when the App is not opened
  • 17.
    WHEN TO USEA SERVICE? ▸ Rule of thumb to distinguish between AsyncTask and Services: ▸ AsyncTask —> quick (< 1 second), inside the app
 (e.g. download user avatar, update UI from background) ▸ Service —> longer (> 1 second), also when app closes
 (e.g. download mp3 in background)
  • 18.
    BROADCAST RECEIVERS ▸ Broadcast= message sent when „events of interest“ occur ▸ Can be inside of your app or between Apps ▸ Can also be sent by the system (e.g. incoming phone call) ▸ You can either publish or subscribe to Broadcasts
  • 19.
    CONTENT PROVIDER ▸ Bestpractice to store data ▸ Makes it possible to share data between apps ▸ provides an interface to easily manage different kinds of data
 (SQLite databases, video, audio, etc.)
  • 20.
  • 22.
    WHAT DOES ITDO? ▸ What the user sees and interacts with ▸ Shows information to your user ▸ Responds to input from your user
  • 23.
    WHAT ARE ACTIVITIESMADE OFF? ▸ Java (or Kotlin) file for the logic and interaction ▸ Interface (.xml) file for defining what the user sees
  • 24.
    WHAT ARE ACTIVITIESMADE OFF? ▸ Java (or Kotlin) file for the logic and interaction ▸ Interface (.xml) file for defining what the user sees
  • 25.
    JAVA PART OFACTIVITY ▸ Indicates which user interface is used ▸ Manages user input ▸ Responds to the activity lifecycle
  • 26.
  • 28.
    LIFECYCLE LITE ▸ Systemtells you the state of your activity ▸ When app is started —> Activity created
 onCreate() ▸ When it is shown on screen —> Activity started
 onStart()
  • 29.
    LIFECYCLE LITE (CONT’D) ▸When no longer in foreground —> Activity paused (and resumed)
 onPause() —> onResume() ▸ When no longer visible —> Activity stopped (and restarted)
 onStop() —> onRestart() ▸ When it is shut down —> Activity destroyed
 onDestroy()
  • 30.
    WHAT ARE ACTIVITIESMADE OFF? ▸ Java (or Kotlin) file for the logic and interaction ▸ Interface (.xml) file for defining what the user sees
  • 31.
    INTERFACE PART OFACTIVITY ▸ Layout file format is .xml ▸ offers a visual editor ▸ creates the layout of the screen with building blocks ▸ showing text —> TextView ▸ show image —> ImageView ▸ let the user input text —> EditText ▸ ordering of blocks is done via layouts
  • 32.
  • 33.
    HOW TO BUILDAN INTERFACE? ▸ All building blocks are Views ▸ Views have properties like: ▸ id ▸ width ▸ height
  • 37.
    HOW TO MANAGEALL THOSE VIEWS? ▸ Views are bundled together in ViewGroups
 (fun fact: these are groups of views) ▸ Layout types define the order of elements in ViewGroups
  • 38.
    COMMON LAYOUTS ▸ LinearLayout ▸RelativeLayout ▸ ConstraintLayout
  • 39.
    COMMON LAYOUTS (CONT’D) ▸Different kinds of List layouts ▸ RecyclerViews (not a real layout but important) ▸ ListView ▸ GridView
  • 40.
    HOW CAN WESTART OTHER ACTIVITIES? ▸ Intents are used (can be thought of like envelopes) ▸ On creation of intent specify Activity (here „ActivityB“) to start and then start it:
  • 41.
    WE CAN ALSOPASS DATA WITH INTENTS ▸ Data is put into Intent with an id by Activity A: ▸ Can be accessed with id by Activity B:
  • 42.
  • 43.
  • 44.
    WHAT TOOLS AREWE USING? ▸ We use the Android SDK ▸ We use Android Studio ▸ Generates .apk (Android Package) which can be installed on device
  • 45.
  • 46.
  • 47.
    ▸ Android DeveloperPortal:
 
 https://developer.android.com/ ▸ Android Trainings in the Developer Portal:
 
 https://developer.android.com/training/basics/firstapp/ index.html
  • 48.
    ▸ Slides forBeginners (also from Google):
 
 https://drive.google.com/drive/u/0/folders/ 0B5Kg0X0yIQ1Pbk5yVGdsSFFjR28 ▸ Free courses on Udacity:
 
 https://de.udacity.com/courses/android
  • 49.
    Thanks! On to theCodelabs…