Yourstory Android Workshop

42
Agenda Introduction Android Components overview Sample Application Android Software Stack Android Components detailed Activity, Service, Provider, Receiver

description

 

Transcript of Yourstory Android Workshop

Page 1: Yourstory Android Workshop

Agenda

● Introduction● Android Components overview● Sample Application● Android Software Stack● Android Components detailed

– Activity, Service, Provider, Receiver

Page 2: Yourstory Android Workshop

History of Android

• Android, Inc. – 2003

• Operating system for digital cameras

• Google Acquisition – 2005

• Open Handset Alliance – Nov 2007

–  Google, HTC, Sony and Samsung

– Qualcomm and Texas Instruments

•  HTC Dream - October 22, 2008

Page 3: Yourstory Android Workshop

Android Application Components

Page 4: Yourstory Android Workshop

Application Components

• Application components are the essential building blocks of an Android application.

Page 5: Yourstory Android Workshop

Application components

● Activity● Service● Broadcast Receiver● Content Provider

Page 6: Yourstory Android Workshop

Application components

Page 7: Yourstory Android Workshop

Activities

• An activity represents a single screen with a user interface

• Example of Activities in Email app

– Email List

– Compose

– Read

Page 8: Yourstory Android Workshop

Activities

Page 9: Yourstory Android Workshop

Services

• A service is a component that runs in the background

• A service does not provide a user interface.

• Example : Music Player, Downloader

Page 10: Yourstory Android Workshop

Services

Page 11: Yourstory Android Workshop

Content Provider

• Content provider

– Allows to share data with other apps

Page 12: Yourstory Android Workshop

Content Provider

Page 13: Yourstory Android Workshop

Content Provider

Page 14: Yourstory Android Workshop

Broadcast Receiver

● Listener of System wide events. ● Examples

– SMS received , Wifi / Bluetooth connected

– Battery Low, Device Rebooted

● No UI● Lightweight ( < 10 seconds )

Page 15: Yourstory Android Workshop

IntentsIntentsIntents

Intents are messages across components.

Like Hyperlinks on the web

Page 16: Yourstory Android Workshop

Intents

● Support interaction between components– e.g. Start a new Activity

– Broadcast messages

● Intents : request for action to be performed

Page 17: Yourstory Android Workshop

17

Types of Intents

MyApp

Activity1 Service1Intent ( myService.class )

OtherAppMyApp

Activity1 Activity2

Explicit Intent

Implicit IntentIntent ( “ACTION” )

Intents

Page 18: Yourstory Android Workshop

Intentsstart new Activity

● Dial a number

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:97412345”));

● Launch a website

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“http://www.google.com”));

Page 19: Yourstory Android Workshop

Intentsstart new Activity

● Launch another activity

Intent i = new Intent(this, SecondActivity.class)

startActivity(i)

Page 20: Yourstory Android Workshop

Intent Filter

● Registers components as capable of receiving Intents

● Matches intents to the component (Activity , Service, Receivers)

● Declared mostly in AndroidManifest.xml

Page 21: Yourstory Android Workshop

Functional Android App

Page 22: Yourstory Android Workshop

<?xml version="1.0" encoding="utf-8"?><manifest> <uses-permission /> <uses-sdk />

<application> <activity>

</activity> </application></manifest>

Application Manifest File

Page 23: Yourstory Android Workshop

<?xml version="1.0" encoding="utf-8"?><LinearLayout> <TextView android:text="I am a TextView" /> <Button android:text="I am a Button" /></LinearLayout>

XML Snippet

Page 24: Yourstory Android Workshop

Preview

Page 25: Yourstory Android Workshop

Layouts

• Linear Layout

• Relative Layout

• List View

• Grid View

Page 26: Yourstory Android Workshop

Linear Layout

<?xml version="1.0" encoding="utf-8"?><LinearLayout android:orientation="vertical" > <TextView android:text="I am a TextView" /> <Button android:text="I am a Button" /></LinearLayout>

Page 27: Yourstory Android Workshop

Linear Layout

<?xml version="1.0" encoding="utf-8"?><LinearLayout android:orientation=“horizontal" > <TextView android:text="I am a TextView" /> <Button android:text="I am a Button" /></LinearLayout>

Page 28: Yourstory Android Workshop

Layouts

Grid ViewList View

Page 29: Yourstory Android Workshop

UI Widgets

Page 30: Yourstory Android Workshop

Sample App

<Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=“I am a Button"/>

Button myButton =(Button)findViewById(R.id.my_button);

Page 31: Yourstory Android Workshop

Sample Apppublic void (View v){

// action }

Add this in XML fileandroid:onClick="myMethod"

Page 32: Yourstory Android Workshop

Sample App

● Extend this to create SecondActivity● invoked on clicking the button

Page 33: Yourstory Android Workshop

Inside the APK● Compiled Java source● Libraries ● XML files for UI, strings● Resources – Images etc● Android Manifest

Page 34: Yourstory Android Workshop

Android Software Stack

● Kernel● Libraries / Runtime● Application Framework● Applications

Page 35: Yourstory Android Workshop

Android Software Stack

Page 36: Yourstory Android Workshop

Linux kernel

• Android built on Linux 2.6 kernel

• Provides security, memory management, process management, network stack, and driver model

• Abstraction layer between hardware and the software stack

Page 37: Yourstory Android Workshop

Libraries

• A set of C/C++ libraries exposed to developers through the application framework

Page 38: Yourstory Android Workshop

Application Framework

Page 39: Yourstory Android Workshop

Application Framework

Page 40: Yourstory Android Workshop

Applications

Page 41: Yourstory Android Workshop

Summary

● Android Components● Android Sample Program● Activity, Services, Broadcast Receiver● Intents● Android Stack

Page 42: Yourstory Android Workshop

Contact

[email protected]

http://belimitless.co