Android 101 Introduction to Android Development Andy Scherzinger Spare-time Android Dev AndyScherzinger 28th Jan. 2016
Topics • Dev Setup • File System Structure • Activities & Fragments • Handle Fragmentation • The little Things
Dev Setup Tool Chain Java Language Gradle Build System Android Studio IDE Android Studio icon CC BY 2.5 Google Inc.
Android Studio Coding Environment & Debugger SDK Manager Gradle Integration Android Device Monitor Android Virtual Device Manager Android Studio icon CC BY 2.5 Google Inc.
Code to Binary Java Byte Code Java Byte Code Java Source Code Java Source Code Java Compiler Java Compiler Dalvik Byte Code Dex Compiler Java Byte Code Dalvik Byte Code Dalvik VM Android Runtime (ART) Java VM https://github.com/devacademy/android-fundamental-one/blob/master/modules/stack.md
File System Structure * Grid, List, UI Partials • AndroidManifest.xml  your App‘s definition • build.gradle,…  your build files • src/java  douh! your implementation • src/res – anim  custom animations – drawable  graphics (pixel, patch9, vector-xml, etc.) – layout  XML Layouts for Activities, Fragments, *-Items – menu  XML Menu Files – raw  any non-specific files – values  l18n resources, static (array) data, configurations – xml  Preference Screen, Sync Adapter, etc.
Fragment Orchestration Source: http://developer.android.com/training/basics/fragments/fragment-ui.html Fragments are UI modules orchestrated via Activities Fragment A Fragment B Fragment A Fragment B Activity 1 Activity 1 Activity 2 Intent
Activities & Fragments – Activity Lifecycle Source: http://developer.android.com/training/basics/activity-lifecycle/starting.html Created Started (visible) Resumed (visible) Paused (part. visible) Stopped (hidden) Destroyed onResume() onStart() onStart() onDestroy() onStop() onPause() onResume() onRestart() Android 1 2 3 • (1) Initialize UI • (2) Checks (e.g. GPS enabled) • (3) Activity running - Woohoo! onCreate()
Activities & Fragments – Activity State Save Source: http://developer.android.com/training/basics/activity-lifecycle/recreating.html Created Resumed (visible) Destroyed onRestoreInstanceState() onSaveInstanceState() Android 2 3 1 • (1) save your state • (2) / (3) restore the state onCreate() Resumed (visible)
Fragmentation Resolution & Display Size Android Versions http://opensignal.com/reports/2015/08/android-fragmentation/ - http://developer.android.com/about/dashboards/index.html
Target Versions and Sizes • src/res – drawable-hdpi-v11  used for Android 11 and up – layout-w600dp-land  used in landscape w/ at least 600dp width
Call Version depending code • src/java if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { builder.setIconAttribute(android.R.attr.alertDialogIcon); }…
Backwards Compatibility via Support Lib • Add libs to build.gradle dependencies { compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' }
…and hack away… • UI: AppCompatButton, Drawer, Material Theme, AppCompatDialog, … • Functionality: e.g. ContextCompat.checkSelfPermission  Android M Permission System Implementation Backwards Compatibility via Support Lib
The (many) little Things…CodeUIMisc • Use Support Lib right from the beginning • Use Activities to manage Fragments • Use Fragments to implement the UI • onCreate is monitored by the Android Runtime and is part of the UI Thread  time consuming work needs to be done asynchronously (!) • Style UI via style xml files not via specific view attributes in layout xml files • Define a color palette (colors.xml), same for dimensions (dimens.xml) • Prefix layout files (activity_, fragment_, listItem_, …) • Re-use elements using <include> (and <merge> in the to be included layout file) • compileTarget is your Frenemy, test thoroughly • Don‘t set maxSdkVersion • Be specific about your dependencies (2.2.0 not 2.2.+) • Don‘t use too many libs (65k method limit!) • Launcher icon(s) in mipmap folder when generating separate APKs for diff. densities
Let‘s check out some code  DEMO
Topics we didn‘t talk about… • Network / Communication • Persistence • Service / AsyncTask / Loader / Event Bus • Permission System • Sensors
Some links to get you started… • Android Tutorials: – http://developer.android.com/training/index.html – https://www.udacity.com/courses/android • Helpful Github Projects – https://github.com/android10/Android-CleanArchitecture – https://github.com/ribot/android-guidelines – https://github.com/txusballesteros/Android-Clean-Testing – https://github.com/ribot/android-boilerplate • Exemplary Apps on Github to play around – https://github.com/WhisperSystems/Signal-Android – https://github.com/owncloud/android • Icons: – https://materialdesignicons.com/

Android 101 - Introduction to Android Development

  • 1.
    Android 101 Introduction toAndroid Development Andy Scherzinger Spare-time Android Dev AndyScherzinger 28th Jan. 2016
  • 2.
    Topics • Dev Setup •File System Structure • Activities & Fragments • Handle Fragmentation • The little Things
  • 3.
    Dev Setup Tool Chain Java LanguageGradle Build System Android Studio IDE Android Studio icon CC BY 2.5 Google Inc.
  • 4.
    Android Studio Coding Environment& Debugger SDK Manager Gradle Integration Android Device Monitor Android Virtual Device Manager Android Studio icon CC BY 2.5 Google Inc.
  • 5.
    Code to Binary JavaByte Code Java Byte Code Java Source Code Java Source Code Java Compiler Java Compiler Dalvik Byte Code Dex Compiler Java Byte Code Dalvik Byte Code Dalvik VM Android Runtime (ART) Java VM https://github.com/devacademy/android-fundamental-one/blob/master/modules/stack.md
  • 6.
    File System Structure *Grid, List, UI Partials • AndroidManifest.xml  your App‘s definition • build.gradle,…  your build files • src/java  douh! your implementation • src/res – anim  custom animations – drawable  graphics (pixel, patch9, vector-xml, etc.) – layout  XML Layouts for Activities, Fragments, *-Items – menu  XML Menu Files – raw  any non-specific files – values  l18n resources, static (array) data, configurations – xml  Preference Screen, Sync Adapter, etc.
  • 7.
    Fragment Orchestration Source: http://developer.android.com/training/basics/fragments/fragment-ui.html Fragmentsare UI modules orchestrated via Activities Fragment A Fragment B Fragment A Fragment B Activity 1 Activity 1 Activity 2 Intent
  • 8.
    Activities & Fragments –Activity Lifecycle Source: http://developer.android.com/training/basics/activity-lifecycle/starting.html Created Started (visible) Resumed (visible) Paused (part. visible) Stopped (hidden) Destroyed onResume() onStart() onStart() onDestroy() onStop() onPause() onResume() onRestart() Android 1 2 3 • (1) Initialize UI • (2) Checks (e.g. GPS enabled) • (3) Activity running - Woohoo! onCreate()
  • 9.
    Activities & Fragments –Activity State Save Source: http://developer.android.com/training/basics/activity-lifecycle/recreating.html Created Resumed (visible) Destroyed onRestoreInstanceState() onSaveInstanceState() Android 2 3 1 • (1) save your state • (2) / (3) restore the state onCreate() Resumed (visible)
  • 10.
  • 11.
    Target Versions andSizes • src/res – drawable-hdpi-v11  used for Android 11 and up – layout-w600dp-land  used in landscape w/ at least 600dp width
  • 12.
    Call Version dependingcode • src/java if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { builder.setIconAttribute(android.R.attr.alertDialogIcon); }…
  • 13.
    Backwards Compatibility via SupportLib • Add libs to build.gradle dependencies { compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' }
  • 14.
    …and hack away… •UI: AppCompatButton, Drawer, Material Theme, AppCompatDialog, … • Functionality: e.g. ContextCompat.checkSelfPermission  Android M Permission System Implementation Backwards Compatibility via Support Lib
  • 15.
    The (many) littleThings…CodeUIMisc • Use Support Lib right from the beginning • Use Activities to manage Fragments • Use Fragments to implement the UI • onCreate is monitored by the Android Runtime and is part of the UI Thread  time consuming work needs to be done asynchronously (!) • Style UI via style xml files not via specific view attributes in layout xml files • Define a color palette (colors.xml), same for dimensions (dimens.xml) • Prefix layout files (activity_, fragment_, listItem_, …) • Re-use elements using <include> (and <merge> in the to be included layout file) • compileTarget is your Frenemy, test thoroughly • Don‘t set maxSdkVersion • Be specific about your dependencies (2.2.0 not 2.2.+) • Don‘t use too many libs (65k method limit!) • Launcher icon(s) in mipmap folder when generating separate APKs for diff. densities
  • 16.
    Let‘s check outsome code  DEMO
  • 17.
    Topics we didn‘ttalk about… • Network / Communication • Persistence • Service / AsyncTask / Loader / Event Bus • Permission System • Sensors
  • 18.
    Some links toget you started… • Android Tutorials: – http://developer.android.com/training/index.html – https://www.udacity.com/courses/android • Helpful Github Projects – https://github.com/android10/Android-CleanArchitecture – https://github.com/ribot/android-guidelines – https://github.com/txusballesteros/Android-Clean-Testing – https://github.com/ribot/android-boilerplate • Exemplary Apps on Github to play around – https://github.com/WhisperSystems/Signal-Android – https://github.com/owncloud/android • Icons: – https://materialdesignicons.com/

Editor's Notes

  • #6 Dalvik makes use of JIT (just in time) compilation. Thus each time the app is run, the part of the code required for its execution is going to becompiled to machine code at that moment. ART compiles the Dalvik bytecode into a system-dependent binary during install (thus only once).