Slide 1

Slide 1 text

ANDROID APPLICATIONS DEVELOPMENT: A QUICK START GUIDE Sergii Zhuk Android Developer at DAXX BV Kyiv, Bibliotech Talks, 2015-04-28 1

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Application execution 4 Efficient Android Threading by Anders Goransson, O'Reilly Media, Inc., 2014

Slide 5

Slide 5 text

Android OS Distribution – 04-2015 https://developer.android.com/about/dashboards/index.html 5

Slide 6

Slide 6 text

Android: not only smartphones 6

Slide 7

Slide 7 text

Android: not only smartphones 7

Slide 8

Slide 8 text

Android: not only smartphones 8

Slide 9

Slide 9 text

Native vs Hybrid Mobile apps 9 http://www.addthis.com/blog/2014/10/27/7-things-to-consider-when-making-ios-and-android-apps-with-cordova-or-phonegap/

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

So, let’s start! • JDK • Android SDK • IDE (Eclipse, IntelliJIDEA, Android Studio) • Gradle build system (optional) 11

Slide 12

Slide 12 text

12 HelloWorld (1)

Slide 13

Slide 13 text

HelloWorld (2) 13

Slide 14

Slide 14 text

14 HelloWorld (3)

Slide 15

Slide 15 text

Launch your app • Emulator supplied with Android SDK • Genymotion emulator (based on Oracle VirtualBox) • On your smartphone 15

Slide 16

Slide 16 text

AndroidManifest.xml 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Permissions: all or nothing 18

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Multiple screens support (1) 20 • Density-independent pixel (dp) – virtual pixel • “wrap_content” and “match_parent” special values for flexibility

Slide 21

Slide 21 text

Multiple screens support (2) • MDPI • HDPI • XHDPI • XXHDPI 21 http://developer.android.com/guide/practices/screens_support.html

Slide 22

Slide 22 text

Resources example 22

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

UI building blocks 24 • ViewGroup – abstract container for Views to show them using special rules • View – abstract widget like TextView, EditText, Checkbox

Slide 25

Slide 25 text

25 Layout example

Slide 26

Slide 26 text

Layout example 26

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

28 Common layouts – adapter-based List View Grid View

Slide 29

Slide 29 text

Adapter 29

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

Activity stack 31 Efficient Android Threading by Anders Goransson, O'Reilly Media, Inc., 2014

Slide 32

Slide 32 text

Activity workflow 32

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Save application data • SharedPreferences (key/value pairs) • Files (internal/external storage) • SQLite database 34

Slide 35

Slide 35 text

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/

Slide 36

Slide 36 text

• 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//databases 36 SQLite in Android

Slide 37

Slide 37 text

External database access 37 http://independent.academia.edu/parthiban6

Slide 38

Slide 38 text

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/

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Use Case: Facebook integration 43

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

How to build your app • In IDE  • Old school: Ant, Maven • Gradle 46

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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']) }

Slide 49

Slide 49 text

Where to publish your app • Google Play Store • Samsung Apps • Amazon Appstore for Android • Asian application stores 49

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Monetizing your app: Play Store • Paid apps – Play Store takes 30% – Android users don’t like to pay • Ads • Donations • Freemium 52

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Get a job: where and how? 54

Slide 55

Slide 55 text

• 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?

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

Useful resources • Udacity “UD853 - Developing Android Apps” • Coursera “Mobile Cloud Computing with Android” • Lynda, Udemy, Stanford Online • AppTractor Podcast (in Russian) 57

Slide 58

Slide 58 text

Thanks! Contact me: [email protected] http://ua.linkedin.com/in/sergiizhuk http://fb.com/sergii.zhuk 58