+ All Categories
Home > Technology > Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Date post: 14-Jan-2015
Category:
Upload: duckma
View: 116 times
Download: 0 times
Share this document with a friend
Description:
 
Popular Tags:
61
2014.02.06 - Introduction to Android Development* @GDGBrescia *Have a break edition
Transcript
Page 1: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

2014.02.06 - Introduction to Android Development* @GDGBrescia

*Have a break edition

Page 2: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

2

Who I Am

+MatteoGazzurelli

CEO / Android Developer DUCKMA srl - Brescia

@gazzumatteo duckma.com

Page 3: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Introduction to Android*

3

Android, the unknown… *Have a break Edition

Page 4: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Android, the unknown...

•  Mobile Operating System by Android Inc.

•  Bought by Google in 2005

•  Unveiled in 2007

3

Page 5: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Why develop for Android?

•  Is adaptable and functional

•  Very good OS

•  Good Business!

5

Page 6: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Google’s Role

•  Development & Support

•  Google Play

•  Nexus

6

Developers

Page 7: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

7

Android 101 In theory…. and in practice.

Page 8: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Java Based

8

Java Hello World

Java VM

Dalvik VM* (ART 4.4)

Page 9: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

What do I need to know to be a programmer?

•  OOP (Object Oriented Programming)

•  Encapsulation, Inheritance, Polymorphism

•  Interfaces

•  Listeners

•  Packages structure

9

Page 10: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

10

Inside the Droid Architecture & Theory

Page 11: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Android Architecture

11

Application

Application Framework

Libraries Runtime

Kernel Linux

Home, Contacts, Telephone, Browser, …

Managers for Activity, Window, Package, …

SQLite, OpenGL, SSL, … Dalvik VM, Core libs

Driver for Display, Camera, Flash, Wifi, Audio, …

Page 12: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Four pillars of Android

•  Activities

•  Services

•  Broadcast Receivers

•  Content Providers

12

Page 13: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Activities

•  Activity is the main component of Android, represent a single screen with a user interface

•  Is like a form in traditional languages such as Visual Basic or like a single HTML page

13

Page 14: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Activity Lifecycle

14

Page 15: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Fragments

•  Since Android 3.0

•  Represent a portion of the UI in an activity

•  Can combine multiple fragment in a single activity

•  Have their lifecycle

•  Live in a ViewGroup

15

Page 16: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Introduction to Intents

•  Intents are used as a message-passing mechanism that works both within your application, and between applications.

•  Interacts with every components in Android •  Used for:

•  Declare your intention that an Activity or Service be started to perform an action, usually with a piece of data ( startActivity(Intent); )

•  Broadcast that an event (or action) has occurred •  Explicity start a particular Service or Activity

16

Page 17: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Services

•  Application components that can perform long-running operations in the background

•  Doesn’t provide a user interface •  Service is not a separate process or thread •  Service is a simple class, you must implement

separate threads by yourself

17

Page 18: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Service Lifecycle

18

Page 19: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Broadcast Receiver

19

•  A Broadcast receiver is a component that does nothing but receive and react to broadcast announcements

•  Broadcast Intent

•  Your app can: •  Receive and react to system services (ex. Battery low) •  Receive and react to other apps broadcast announcements •  Initiate broadcasts to other apps

Page 20: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Content Provider

•  Content Providers manage access to a structured set of data

•  Are the standard interface that connects data in one process with code running in another process

•  Any application with appropriate permission, can read and write the data

•  Files, SQL Database •  Expose a public URI that uniquely identifies its data set •  “content://…”

20

Page 21: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Content Provider

21

Page 22: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

22

Hands On Down and dirty!

Page 23: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Craftsman tools

23

•  IDE •  Eclipse •  Android Studio

•  Tools: •  ADT (Android Developer Tools) •  Android SDK Tools •  Android Platform Tools •  AVD (Android Virtual Device) / Emulator

Page 24: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Eclipse / Android Studio

24

Page 25: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Android SDK Manager (via ADT)

25

Page 26: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Android Virtual Device Manager (AVD)

26

Page 27: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

LogCat

27

Page 28: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Debug

28

Page 29: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

29

Let’s start a new project Gentlemen start your engines!

Page 30: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

File -> New Project

30

Page 31: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Tutorial

31

Page 32: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Project structure

32

Page 33: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Src

•  Java Classes •  Activity •  Fragment •  Adapter •  Models

•  Organized in Packages

33

Page 34: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Activity Sample Code

34

JAVA package com.example; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override protected void onPause() { super.onPause(); } }

Page 35: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Assets e Lib

•  Assets •  Not optimized and compiled resources

•  Libs

•  External libraries •  Java o C

35

Page 36: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Resources

•  Any other information that are not code •  Stored in config files external to code (but inside the final

apk package) •  Contain

•  Drawable •  Layouts •  Xml •  Values

36

Page 37: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Classe R.java

•  Bridge between activities and resources

•  In gen/

•  Dynamically generated (by Android’s Eclipse plugin) and contains numeric constant referred to every resources of the project

•  Contains only public fields (“public static final”)

37

Page 38: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Resource Example String.xml

38

XML <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Test</string> <string name="action_settings" >Settings</string> <string name="hello_world" >Hello world!</string> </resources>

Page 39: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Layout

•  XML Files

•  Defines the visual structure for a user interface

•  Target many resolutions

39

Page 40: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Layout Example Activity_main.xml

40

XML <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content” android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>

Page 41: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Widget

•  Visual Components of Android •  Button •  TextView •  EditText •  WebView •  ImageView •  …

41

Page 42: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Widget Example Button

42

JAVA

Button myButton = new Button(this); myButton.setText(R.string.button_back); myButton.setLayoutParams(new LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ));

XML

<Button android:id="@+id/button1” android:layout_width="wrap_content” android:layout_height="wrap_content” android:layout_alignLeft="@+id/textView1” android:layout_below="@+id/textView1” android:layout_marginLeft="41dp” android:text="Button” />

Page 43: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Eclipse UI Builder

43

Page 44: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Views

•  Base component for UI (Widget)

•  Layout •  Visual structure of the UI

•  View Groups •  Invisible Container that contains other View or ViewGroup

44

Page 45: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Manifest

•  Contains the essential information about the application •  Version •  Name •  Icon •  Permission •  Features

•  Other elements to declare •  Activity •  Services •  Provider •  Receiver •  uses-sdk •  uses-permission

45

Page 46: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Design Pattern

•  Model – View – Controller •  Activity -> Controller

•  Model – View – Presenter •  Activity -> View

•  In the official Android documentations doesn’t exists any referral to these patterns

46

Page 47: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

What’s new in 4.4 ?

•  Small amount of memory Only 512Mb

•  Print API

•  Share Everywhere

•  Immersive mode

•  Tap To Pay

47

Page 48: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

48

Fragmentation ‘minSdkVersion=“14”’

Page 49: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Android Family Tree

49

1.5 Cupcake 1.6 Donut 2.0 Eclair 2.2 Froyo 2.3 Gingerbread

3.0 Honeycomb

4.0 Ice Cream Sandwich 4.1 Jelly Bean

4.4 KitKat

Page 50: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

January Fragmentation Status

50

Page 51: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

How many Display!

51

Screen Types vs Screen Sizes

Page 52: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Suggestions (No Panic!)

•  Choose the right target of your application •  minSdkVersion=“14”

•  Learn how to use correctly the res. •  Support library •  Test on at least two devices •  Fragmentation can be an advantage

52

Page 53: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

53

Publish Make public your creations!

Page 54: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Markets

•  Google

•  Samsung

•  Amazon

•  Any other market (your)

54

Page 55: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Google Play Store

55

Page 56: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Google Play Store - Publish

56

Page 57: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Google Play Store - Stats

57

Page 58: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

58

Introduction to Android – The End

+MatteoGazzurelli

@gazzumatteo [email protected]

Thank You & Have Fun!

That’s me!

Page 59: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

59

Questions?

Page 60: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

Links & resources

•  Android Developer http://developer.android.com

•  Android Design Guidelines http://developer.android.com/design/

•  Commonsware http://wares.commonsware.com

•  Omnibus – Commonsware https://github.com/commonsguy/cw-omnibus

•  Play Store Publish http://play.google.com/apps/publish/

•  Duckma http://duckma.com 60

Page 61: Matteo Gazzurelli - Introduction to Android Development - Have a break edition

61

Introduction to Android – The End

+MatteoGazzurelli

@gazzumatteo [email protected]

Thank You & Have Fun!

That’s me!


Recommended