Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Apps Development: A Quick Start Guide

Android Apps Development: A Quick Start Guide

Presented at Bibliotech Tech Talks in Kiev, April 2015.

More Android stuff:
https://medium.com/@sergii
https://twitter.com/sergiizhuk

Sergii Zhuk

April 28, 2015
Tweet

More Decks by Sergii Zhuk

Other Decks in Programming

Transcript

  1. ANDROID APPLICATIONS DEVELOPMENT: A QUICK START GUIDE Sergii Zhuk Android

    Developer at DAXX BV Kyiv, Bibliotech Talks, 2015-04-28 1
  2. Agenda • Android platform • How to start • User

    Interface • Basic Android patterns • How to distribute your app • Career of Android Developer • Useful links, books, communities 2
  3. Android OS • Linux but user doesn’t have root rights

    by default • Open Source Project • Each device manufacturer modifies OS for his needs, source code is not available in general 3
  4. Android native apps development • Java: to be executed using

    Dalvik or ART VMs • С/С++: Native Development Kit – to develop high-performance modules, will be also launched using VMs 10
  5. So, let’s start! • JDK • Android SDK • IDE

    (Eclipse, IntelliJIDEA, Android Studio) • Gradle build system (optional) 11
  6. Launch your app • Emulator supplied with Android SDK •

    Genymotion emulator (based on Oracle VirtualBox) • On your smartphone 15
  7. Manifest file - AndroidManifest.xml • Permissions (Internet access, storage, …)

    • Min and target API version • Special hardware requests (Camera, Bluetooth, …) • Some custom Google tools (Play Services, Google Maps) • Definition of Activities and Services 17
  8. Application resources • Images, Strings, layouts • Separately from application

    source code • Unique integer ID will be generated for each resource name which could be used as a constant • You can supply alternative resource with the same name to specific folders indicating screen size, locale, screen rotation etc 19
  9. Multiple screens support (1) 20 • Density-independent pixel (dp) –

    virtual pixel • “wrap_content” and “match_parent” special values for flexibility
  10. Multiple screens support (2) • MDPI • HDPI • XHDPI

    • XXHDPI 21 http://developer.android.com/guide/practices/screens_support.html
  11. Multiple screens support (3) 23 Density Device Screen resolution MDPI

    Galaxy Tab 3 1280*800 HDPI HTC Desire 480*800 XHDPI Nexus 7 1200*1920 XXHDPI Nexus 5 1080*1920
  12. UI building blocks 24 • ViewGroup – abstract container for

    Views to show them using special rules • View – abstract widget like TextView, EditText, Checkbox
  13. 25 Layout example <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="16dp" android:gravity="center_horizontal" android:orientation="vertical">

    <TextView android:id="@+id/text" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:text="I am a TextView"/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I am a Button"/> </LinearLayout>
  14. Common ViewGroups 27 Horizontal or vertical row, easy to stretch

    Position of each element could be configured depending on parent and/or neighbors Linear Layout Relative Layout
  15. Activity • Provides a screen with which user can interact

    to do something • At least one activity per application • Notified of screen navigation/device state change through lifecycle callback methods 30
  16. Service • Used for long-running operations in the background and

    does not provide a user interface • Runs on the main thread of hosting process, could be configured to use a separate thread 33
  17. SQLite in Android • Implements most of the SQL-92 standard

    for SQL • All data for the app is stored in one file (if wasn’t configured separately) • Cross-platform – also used in iOS and Blackberry 35 http://www.grokkingandroid.com/sqlite-in-android/
  18. • Serverless, always installed in the system • By default

    doesn’t use encryption • By default is stored in the app folder, could be opened by external tools on rooted devices: /data/data/<package-name>/databases 36 SQLite in Android
  19. SQLite Android data types Type Meaning INTEGER Any number which

    is not a floating point number REAL Floating-point numbers (8-Byte IEEE 754 – i.e. double precision) TEXT Any String and also single characters (UTF-8, UTF-16BE or UTF-16LE) BLOB A binary blob of data 38 http://www.grokkingandroid.com/sqlite-in-android/
  20. Content provider • Presents data to external applications as one

    or more tables like in a relational database • System-provided Content providers examples: Contacts, list of music tracks, list of gallery images • Thread safe 39
  21. Broadcast receiver • Allows to register for system or application

    events • Operates with Intent which is a lightweight messaging object • Could be Asynchronous - all receivers of the broadcast are run in an undefined order, often at the same time or Ordered 40
  22. System broadcast messages example Event Description Intent.ACTION_BOOT_COMPLETED Boot completed Intent.ACTION_POWER_CONNECTED

    Power got connected to the device Intent.ACTION_POWER_DISCONNECTED Power got disconnected to the device Intent.ACTION_BATTERY_LOW Triggered on low battery. Typically used to reduce activities in your app which consume power Intent.ACTION_PHONE_STATE_CHANGED The call state (cellular) on the device has changed 41
  23. Use Case: Interaction with backend • Synchronous HTTP request in

    the separate thread - OR use external library (Retrofit, Volley, Enroscar) • Parse result (for json - GSON is de-facto standard) • Post result to the UI 42
  24. Use Case: geolocation 44 • GPS, Cell-ID, Wi-Fi. Need to

    declare permissions at AndroidManifest.xml • “Cold start”: wait for GPS • Callback on device being moved • Rapid battery drain problem
  25. Automated application testing • No?  • Espresso and JUnit

    - uses emulator or real device – Slow • Robolectric: texts executed inside your desktop PC JVM • Blackbox UI testing (Robotium) 45
  26. How to build your app • In IDE  •

    Old school: Ant, Maven • Gradle 46
  27. Gradle • Good IDE integration • Dependency management (Maven, Ivy)

    out of the box • Sign applications configuration out of the box • Backward compatibility breaks quite often on new Gradle version update 47
  28. Gradle script: shortened example 48 android { compileSdkVersion 15 buildToolsVersion

    "22.0.1" defaultConfig { applicationId "org.sergez.myapplication.app" minSdkVersion 9 targetSdkVersion 22 versionCode 1 versionName "1.0" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_6 targetCompatibility JavaVersion.VERSION_1_6 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard.txt'), 'p-r.pro' } } } dependencies { compile 'com.android.support:support-v4:22.0.0' compile 'com.android.support:appcompat-v7:22.+' compile fileTree(dir: 'libs', include: ['*.jar']) }
  29. Where to publish your app • Google Play Store •

    Samsung Apps • Amazon Appstore for Android • Asian application stores 49
  30. Google Play Store (1) • $25 for Developer Account with

    publishing rights • Application is available in Play Store in 3-6 hours after being published • Auto-moderation in general, manual post- moderation could be applied in some cases 50
  31. Google Play Store (2) • Allows to publish app in

    alpha- and beta test modes • Customization of app visibility for different countries and devices • User could rate the app and leave a feedback, developer could respond to this feedback 51
  32. Monetizing your app: Play Store • Paid apps – Play

    Store takes 30% – Android users don’t like to pay • Ads • Donations • Freemium 52
  33. Keep in mind when starting a new project • Android

    target version • Special UI design for tablets • Availability of mockups and flow explanation • Amount of non-standard UI elements • UI will be outdated in 0.5-2 years 53
  34. • Freelance • Android app as only a small part

    of a big product • Mobile development company (outsourcing) • Mobile-first product 55 Get a job: where and how?
  35. Useful resources • https://developer.android.com • http://android-developers.blogspot.com/ • E-book «The Busy

    Coder's Guide to Android Development» • Android Performance Patterns – YouTube and G+ • DOU.ua Android Digest 56
  36. Useful resources • Udacity “UD853 - Developing Android Apps” •

    Coursera “Mobile Cloud Computing with Android” • Lynda, Udemy, Stanford Online • AppTractor Podcast (in Russian) 57