android app development (basics)

44
Mobile application development Android introduction Alberto Rubalcaba Oracle Certified Professional, Java SE Programmer

Upload: alberto-rubalcaba-stockman

Post on 02-Jul-2015

124 views

Category:

Software


1 download

DESCRIPTION

Introduction to Android Platform Development. Contains architecture, design and development principles and code examples

TRANSCRIPT

Page 1: Android App Development (Basics)

Mobile applicationdevelopment

Android introduction

Alberto Rubalcaba

Oracle Certified Professional, Java SE Programmer

Page 2: Android App Development (Basics)

¿What is Android?

Open source, open platform for mobile development

All the SDK, API and platform source is available

No need for licence or app review

You can replace any system app with your own

Official development site: developer.android.com

Page 3: Android App Development (Basics)

How it works?

Components architecture model

Every component provides his interface

Java programming

Page 4: Android App Development (Basics)

Useful programming tips

Avoid creating objects

Use native functions

Prefer static

Avoid internal getter o setter

Declare constants final

Avoid floats and enums

Page 5: Android App Development (Basics)

Android Architecture

Page 6: Android App Development (Basics)

Project architecture

Page 7: Android App Development (Basics)

Design principles

Delight me in surprising

Real objects are more fun than buttons and menus

Let me make it mine

Get to know me

Keep it brief

Pictures are faster than words

Decide for me, but let me have the final say

http://developer.android.com/design/get-started/principles.html

Page 8: Android App Development (Basics)

App components

Activities

Services

Content providers

Broadcast receivers

Page 9: Android App Development (Basics)

Activity life cycle

Page 10: Android App Development (Basics)

Services

Perform long operations on background

Runs trough applications

A component can bind to a service to interact with and performinterprocess communication (IPC)

Service statesStarted

Bound

http://developer.android.com/guide/components/services.html

Page 11: Android App Development (Basics)

Content providers

Manages access to structured set of data

Provide mechanisms for defining data security

Connects data in one process with code running in another process

http://developer.android.com/guide/topics/providers/content-providers.html

Page 12: Android App Development (Basics)

Broadcast receivers

Send broadcasts across applications

Registered by the context of the application dynamically

Registered statically in the android manifest

http://developer.android.com/reference/android/content/BroadcastReceiver.html

Page 13: Android App Development (Basics)

Intents

Abstract description of an operation to be performed

Can be used to start activities, send broadcasts, start or bind services

Intent structureAction. The general action to be performed

Data. The data to operate on, such a record on contacts, as a URI

Category. Gives additional information about the action to execute

Type. Specifies an explicit type (MIME types) of the intent data

Extras. This is a Bundle of additional information

http://developer.android.com/reference/android/content/Intent.html

Page 14: Android App Development (Basics)

Application Context

Interface to global information about an application environment

Abstract class whose implementation is provided by Android system

Allows access to application-specific resources and classes

Calls for application-level operations such as launching activities, broadcasting and receiving intents

http://developer.android.com/reference/android/content/Context.html

Page 15: Android App Development (Basics)

Bundle

Mapping to String values to various Parcelable types (Serializable)

Has methods to put <key,value>’s to the map

Has methods to get <key,value>’s from the map

Has a method to clear() the whole map

http://developer.android.com/reference/android/os/Bundle.html

Page 16: Android App Development (Basics)

Manifest

All applications must have a manifest in the root directory

Presents essential information the system must have before runningthe app

It names the java package for the application

It describes the components of the application

It determines which processes will host application components

Declares permissions to access protected parts of the API

http://developer.android.com/guide/topics/manifest/manifest-intro.html

Page 17: Android App Development (Basics)

User interface

Built using View and ViewGroup objects

A View is an object that draws something on the screen to interactwith

A ViewGroup is an object that holds other View’s and ViewGroup’sobjects in order to define the layout of the app

http://developer.android.com/guide/topics/ui/index.html

Page 18: Android App Development (Basics)

User interface layout

Page 19: Android App Development (Basics)

User interface layout

The effective way to define your layout is via XML

The name of the XML element is respective to the Android class itrepresents

http://developer.android.com/guide/topics/ui/declaring-layout.html

Page 20: Android App Development (Basics)

Example

Page 21: Android App Development (Basics)

Layouts

Defines the visual structure for a user interface

After declaring a layout in XML, it should be saved in the res/layoutproject directory

When you compile your app, each layout is compiled into a View resource

The layout should be loaded in the Activity.onCreate(Bundle b) method

Call setContentView(R.layout.my_view)

Page 22: Android App Development (Basics)

Common Layouts

Linear layout

Relative layout

Web view

List view

Grid view

Page 23: Android App Development (Basics)

Input controls

Interactive components in your UI

Just add the control to the xml

http://developer.android.com/guide/topics/ui/controls.html

Page 24: Android App Development (Basics)

Common controls

Page 25: Android App Development (Basics)

Event listeners

Page 26: Android App Development (Basics)

Event listener example

Page 27: Android App Development (Basics)

Menus

Common UI component

Appears when the user touch the menu soft/hard button

Types of menusOptions menu and action bar

Context menu and contextual action menu

Pop up menu

http://developer.android.com/guide/topics/ui/menus.html

Page 28: Android App Development (Basics)

Defining a menu in XML

Defined in res/menu

Inflate the menu in the onCreate(Bundle b) method

Easier to visualize the menu structure in XML

Separates the content of the menu from the behavioral code

Allows to create alternative menu configurations

Allows to create submenus

Page 29: Android App Development (Basics)

Menu example

Page 30: Android App Development (Basics)

Handling menu events

Page 31: Android App Development (Basics)

Dialogs

AlertDialog

DatePickerDialog

TimePickerDialog

CustomDialogs

http://developer.android.com/guide/topics/ui/dialogs.html

Page 32: Android App Development (Basics)

Dialogs (1)

Dialogs contentTitle

Optional, should be used only when the content area is occupied by a detailed message, list or custom layout

Content areaThis can display a message, a list or a custom layout

Action buttonsThere should be no more than 3 action buttons in a dialog

Page 33: Android App Development (Basics)

Dialogs (2)

The alertDialog.Builder class provides API’s that allow you to createan AlertDialog with the kinds of contents, including custom layouts

Page 34: Android App Development (Basics)

Dialogs (3)

To add action buttons call the setPositiveButton() and setNegativeButton() methods

Page 35: Android App Development (Basics)

Dialogs (4)

Traditional single-choice list

Persistent single-choice list (radio buttons)

Persistent multiple-choice list (check boxes)

Page 36: Android App Development (Basics)

Toasts

Provides a simple feedback about an operation in a small popup

Fills the amount of space required for the message

http://developer.android.com/guide/topics/ui/notifiers/toasts.html

Page 37: Android App Development (Basics)

Toasts (1)

Instantiate a Toast object with one of the makeToast() methods

This method takes three parametersApplication context

String message

Toast duration (millis)

Page 38: Android App Development (Basics)

Custom Toasts

You can create customized layout for your toast notification

Define a view XML layout

Pass the root view object to the setView(View) method

Page 39: Android App Development (Basics)

Custom Toasts

You must use the ID of your custom layout to inflate it from the XML

Page 40: Android App Development (Basics)

Sensors

Page 41: Android App Development (Basics)

Sensors (1)

Sensor framworkSensorManager

Sensor

SensorEvent

SensorEventListener

http://developer.android.com/guide/topics/sensors/index.html

Page 42: Android App Development (Basics)

Sensors (2)

Identifying sensorsGet the sensor service

Get the sensor that you are looking for

Page 43: Android App Development (Basics)

Sensors (3)

• Monitoring events

Page 44: Android App Development (Basics)

Let’s code