46
Android Development May 2014

Android Development Tutorial

Embed Size (px)

DESCRIPTION

Android Quick Start Tutorial

Citation preview

Page 1: Android Development Tutorial

Android DevelopmentMay 2014

Page 2: Android Development Tutorial

Agenda

• Why mobile development?

• The good and bad of android

• How to start with Android Development

• App Components

• Types of layouts

• Input controls

• UI Thread

• Notifications

Page 3: Android Development Tutorial

Why mobile development?

Page 4: Android Development Tutorial

Why mobile development?

Page 5: Android Development Tutorial

Why mobile development?

Page 6: Android Development Tutorial

The good and bad of Android

• Java• Open source• Google Play Store• Various Manufacturers

Page 7: Android Development Tutorial

How to start with Android Development

Page 8: Android Development Tutorial

How to start with Android Development

• Android apps are written in the Java programming language.

• The Android SDK tools compile your code into an APK.

• The Android operating system is a multi-user Linux system in which each app is a different

user.

• However, there are ways for an app to share data with other apps and for an app to access

system services:

• It's possible to arrange for two apps to share the same Linux user ID.

• An app can request permission to access device data such as the user's contacts, SMS

messages, the mountable storage (SD card), camera, Bluetooth, and more. All app

permissions must be granted by the user at install time.

Page 9: Android Development Tutorial

Android Manifest

• Describes the components of the application. It names the classes that implement each of

the components and publishes their capabilities (for example, which Intent messages they

can handle). These declarations let the Android system know what the components are

and under what conditions they can be launched.

• It declares which permissions the application must have in order to access protected parts

of the API and interact with other applications.

• It also declares the permissions that others are required to have in order to interact with

the application's components.

Page 10: Android Development Tutorial

Android development environment

Page 11: Android Development Tutorial

Android Studio

• Android focused IDE.

• Powerful code editing (smart editing, code refactoring).

• Rich layout Editor

• Lint tool analysis.

• Color and text preview.

• Template based wizards.

Page 12: Android Development Tutorial

Native emulator

Page 13: Android Development Tutorial

Genymotion

• Fast!

• Easy to install and configure.

• Control powerful sensors to test specialized features on your app.

Page 14: Android Development Tutorial

Demo: Android Studio

Page 15: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 16: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 17: Android Development Tutorial

Activities

• An Activity is an Application component that provides a screen with which users can

interact.

• Each activity is given a window in which to draw its user interface.

• An application usually consists of multiple activities.

• Typically, one activity in an application is specified as the "main" activity, which is

presented to the user when launching the application for the first time.

• Each activity can then start another activity in order to perform different actions.

• Each time a new activity starts, the previous activity is stopped, but the system preserves

the activity in a stack (the "back stack").

Page 18: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 19: Android Development Tutorial

Services

• A Service is an application component that can perform long-running operations in the

background and does not provide a user interface.

• Another application component can start a service and it will continue to run in the

background even if the user switches to another application.

• Additionally, a component can bind to a service to interact with it and even perform

interprocess communication (IPC). For example, a service might handle network

transactions, play music, perform file I/O, or interact with a content provider, all from the

background.

Page 20: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 21: Android Development Tutorial

Content providers

• A content provider manages a shared set of app data. You can store the data in the file

system, an SQLite database, on the web, or any other persistent storage location your app

can access.

• Through the content provider, other apps can query or even modify the data (if the

content provider allows it).

• For example, the Android system provides a content provider that manages the user's

contact information. As such, any app with the proper permissions can query part of the

content provider to read and write information about a particular person.

• Content providers are also useful for reading and writing data that is private to your app

and not shared.

Page 22: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 23: Android Development Tutorial

Broadcast receiver

• A broadcast receiver is a component that responds to system-wide broadcast

announcements.

• Many broadcasts originate from the system—for example, a broadcast announcing that

the screen has turned off, the battery is low, or a picture was captured.

• Apps can also initiate broadcasts—for example, to let other apps know that some data has

been downloaded to the device and is available for them to use.

• Although broadcast receivers don't display a user interface, they may create a status bar

notification to alert the user when a broadcast event occurs.

Page 24: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 25: Android Development Tutorial

Intents

• Intents bind individual components to each other at runtime, whether the component

belongs to your app or another.

• For activities and services, an intent defines the action to perform (for example, to "view"

or "send" something) and may specify the URI of the data to act on (among other things

that the component being started might need to know).

• In some cases, you can start an activity to receive a result, in which case, the activity also

returns the result in an Intent.

• For broadcast receivers, the intent simply defines the announcement being broadcast.

Page 26: Android Development Tutorial

App Components

Activities

Services

Content providers

Broadcast receiver

Intents

Views

Page 27: Android Development Tutorial

Views

• All user interface elements in an Android app are built using View and ViewGroup objects.

• A View is an object that draws something on the screen that the user can interact with.

• A ViewGroup is an object that holds other View (and ViewGroup) objects in order to

define the layout of the interface.

• Android provides a collection of both View and ViewGroup subclasses that offer you

common input controls (such as buttons and text fields) and various layout models (such as

a linear or relative layout).

Page 28: Android Development Tutorial

Input controls

• Buttons

• Text Fields

• Checkboxes

• Radio Buttons

• Toggle Buttons

• Spinners

• Pickers

Page 29: Android Development Tutorial

Buttons

Page 30: Android Development Tutorial

Text Fields

Page 31: Android Development Tutorial

Checkboxes, Radio buttons, Toggle buttons

Page 32: Android Development Tutorial

Spinners

Page 33: Android Development Tutorial

Demo: Intents

Page 34: Android Development Tutorial

Types of layouts: Common Layouts

Page 35: Android Development Tutorial

Types of layouts: Layouts with an adapter

Page 36: Android Development Tutorial

UI Thread

● It is in charge of dispatching events to the appropriate user interface widgets, including

drawing events.

● Interacts with components from the Android UI toolkit

● There are simply two rules to Android's single thread model:

● Do not block the UI thread

● Do not access the Android UI toolkit from outside the UI thread

Page 37: Android Development Tutorial

AsyncTask

• onPreExecute: Invoked before the task is executed ideally before doInBackground

method is called on the UI thread. This method is normally used to setup the task like

showing progress bar in the UI.

• doInBackground: Code running for long lasting time should be put in doInBackground

method. When execute method is called in UI main thread, this method is called with the

parameters passed.

• onProgressUpdate: Invoked by calling publishProgress at anytime from doInBackground.

This method can be used to display any form of progress in the user interface.

• onPostExecute: Invoked after background computation in doInBackground method

completes processing. Result of the doInBackground is passed to this method.

Page 38: Android Development Tutorial

UI Thread

Page 39: Android Development Tutorial

Demo: MercadoLibre Search App

Page 40: Android Development Tutorial

Notifications

Page 41: Android Development Tutorial

Notifications

Page 42: Android Development Tutorial

Demo: Notifications

Page 43: Android Development Tutorial

Demo: Play Store

Page 44: Android Development Tutorial

What's next?

Page 45: Android Development Tutorial

What’s next?

Page 46: Android Development Tutorial

Q&A