android applications development: a quick start guide

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

Upload: sergii-zhuk

Post on 28-Jul-2015

70 views

Category:

Mobile


1 download

TRANSCRIPT

Page 1: Android Applications Development: A Quick Start Guide

1

ANDROID APPLICATIONS DEVELOPMENT: A QUICK START GUIDE

Sergii ZhukAndroid Developer at DAXX BV

Kyiv, Bibliotech Talks, 2015-04-28

Page 2: Android Applications Development: A Quick Start Guide

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

Page 3: Android Applications Development: A Quick Start Guide

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

Page 4: Android Applications Development: A Quick Start Guide

4

Application execution

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

Page 5: Android Applications Development: A Quick Start Guide

5

Android OS Distribution – 04-2015

https://developer.android.com/about/dashboards/index.html

Page 6: Android Applications Development: A Quick Start Guide

6

Android: not only smartphones

Page 7: Android Applications Development: A Quick Start Guide

7

Android: not only smartphones

Page 8: Android Applications Development: A Quick Start Guide

8

Android: not only smartphones

Page 9: Android Applications Development: A Quick Start Guide

9

Native vs Hybrid Mobile apps

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

Page 10: Android Applications Development: A Quick Start Guide

10

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

Page 11: Android Applications Development: A Quick Start Guide

11

So, let’s start!

• JDK

• Android SDK

• IDE (Eclipse, IntelliJIDEA, Android Studio)

• Gradle build system (optional)

Page 12: Android Applications Development: A Quick Start Guide

12

HelloWorld (1)

Page 13: Android Applications Development: A Quick Start Guide

13

HelloWorld (2)

Page 14: Android Applications Development: A Quick Start Guide

14

HelloWorld (3)

Page 15: Android Applications Development: A Quick Start Guide

15

Launch your app

• Emulator supplied with Android SDK

• Genymotion emulator (based on Oracle VirtualBox)

• On your smartphone

Page 16: Android Applications Development: A Quick Start Guide

16

AndroidManifest.xml

Page 17: Android Applications Development: A Quick Start Guide

17

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

Page 18: Android Applications Development: A Quick Start Guide

18

Permissions:all or nothing

Page 19: Android Applications Development: A Quick Start Guide

19

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

Page 20: Android Applications Development: A Quick Start Guide

20

Multiple screens support (1)

• Density-independent pixel (dp) – virtual pixel

• “wrap_content” and “match_parent” special values for flexibility

Page 21: Android Applications Development: A Quick Start Guide

21

Multiple screens support (2)

• MDPI

• HDPI

• XHDPI

• XXHDPI

http://developer.android.com/guide/practices/screens_support.html

Page 22: Android Applications Development: A Quick Start Guide

22

Resources example

Page 23: Android Applications Development: A Quick Start Guide

23

Multiple screens support (3)

Density Device Screen resolutionMDPI Galaxy Tab 3 1280*800

HDPI HTC Desire 480*800

XHDPI Nexus 7 1200*1920

XXHDPI Nexus 5 1080*1920

Page 24: Android Applications Development: A Quick Start Guide

24

UI building blocks

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

Page 25: Android Applications Development: A Quick Start Guide

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>

Page 26: Android Applications Development: A Quick Start Guide

26

Layout example

Page 27: Android Applications Development: A Quick Start Guide

27

Common ViewGroups

Horizontal or vertical row, easy to stretch

Position of each element could be configured depending on parent and/or neighbors

Linear Layout Relative Layout

Page 28: Android Applications Development: A Quick Start Guide

28

Common layouts – adapter-based

List View Grid View

Page 29: Android Applications Development: A Quick Start Guide

29

Adapter

Page 30: Android Applications Development: A Quick Start Guide

30

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

Page 31: Android Applications Development: A Quick Start Guide

31

Activity stack

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

Page 32: Android Applications Development: A Quick Start Guide

32

Activity workflow

Page 33: Android Applications Development: A Quick Start Guide

33

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

Page 34: Android Applications Development: A Quick Start Guide

34

Save application data

• SharedPreferences (key/value pairs)

• Files (internal/external storage)

• SQLite database

Page 35: Android Applications Development: A Quick Start Guide

35

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

http://www.grokkingandroid.com/sqlite-in-android/

Page 36: Android Applications Development: A Quick Start Guide

36

• 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

SQLite in Android

Page 37: Android Applications Development: A Quick Start Guide

37

External database access

http://independent.academia.edu/parthiban6

Page 38: Android Applications Development: A Quick Start Guide

38

SQLite Android data types

Type Meaning

INTEGERAny number which is not a floating point number

REALFloating-point numbers (8-Byte IEEE 754 – i.e. double precision)

TEXTAny String and also single characters (UTF-8, UTF-16BE or UTF-16LE)

BLOBA binary blob of data

http://www.grokkingandroid.com/sqlite-in-android/

Page 39: Android Applications Development: A Quick Start Guide

39

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

Page 40: Android Applications Development: A Quick Start Guide

40

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

Page 41: Android Applications Development: A Quick Start Guide

41

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

Page 42: Android Applications Development: A Quick Start Guide

42

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

Page 43: Android Applications Development: A Quick Start Guide

43

Use Case: Facebook integration

Page 44: Android Applications Development: A Quick Start Guide

44

Use Case: geolocation

• 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

Page 45: Android Applications Development: A Quick Start Guide

45

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)

Page 46: Android Applications Development: A Quick Start Guide

46

How to build your app

• In IDE

• Old school: Ant, Maven

• Gradle

Page 47: Android Applications Development: A Quick Start Guide

47

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

Page 48: Android Applications Development: A Quick Start Guide

48

Gradle script: shortened exampleandroid { 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'])}

Page 49: Android Applications Development: A Quick Start Guide

49

Where to publish your app

• Google Play Store

• Samsung Apps

• Amazon Appstore for Android

• Asian application stores

Page 50: Android Applications Development: A Quick Start Guide

50

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

Page 51: Android Applications Development: A Quick Start Guide

51

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

Page 52: Android Applications Development: A Quick Start Guide

52

Monetizing your app: Play Store

• Paid apps– Play Store takes 30%– Android users don’t like to pay

• Ads

• Donations

• Freemium

Page 53: Android Applications Development: A Quick Start Guide

53

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

Page 54: Android Applications Development: A Quick Start Guide

54

Get a job: where and how?

Page 55: Android Applications Development: A Quick Start Guide

55

• Freelance

• Android app as only a small part of a big product

• Mobile development company (outsourcing)

• Mobile-first product

Get a job: where and how?

Page 57: Android Applications Development: A Quick Start Guide

57

Useful resources

• Udacity “UD853 - Developing Android Apps”

• Coursera “Mobile Cloud Computing with Android”

• Lynda, Udemy, Stanford Online

• AppTractor Podcast (in Russian)

Page 58: Android Applications Development: A Quick Start Guide

58

Thanks!

Contact me:[email protected]://ua.linkedin.com/in/sergiizhukhttp://fb.com/sergii.zhuk