Yourstory Android Workshop
-
Upload
arvind-devaraj -
Category
Software
-
view
546 -
download
2
description
Transcript of Yourstory Android Workshop
Agenda
● Introduction● Android Components overview● Sample Application● Android Software Stack● Android Components detailed
– Activity, Service, Provider, Receiver
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
Android Application Components
Application Components
• Application components are the essential building blocks of an Android application.
Application components
● Activity● Service● Broadcast Receiver● Content Provider
Application components
Activities
• An activity represents a single screen with a user interface
• Example of Activities in Email app
– Email List
– Compose
– Read
Activities
Services
• A service is a component that runs in the background
• A service does not provide a user interface.
• Example : Music Player, Downloader
Services
Content Provider
• Content provider
– Allows to share data with other apps
•
Content Provider
Content Provider
Broadcast Receiver
● Listener of System wide events. ● Examples
– SMS received , Wifi / Bluetooth connected
– Battery Low, Device Rebooted
● No UI● Lightweight ( < 10 seconds )
IntentsIntentsIntents
Intents are messages across components.
Like Hyperlinks on the web
Intents
● Support interaction between components– e.g. Start a new Activity
– Broadcast messages
● Intents : request for action to be performed
17
Types of Intents
MyApp
Activity1 Service1Intent ( myService.class )
OtherAppMyApp
Activity1 Activity2
Explicit Intent
Implicit IntentIntent ( “ACTION” )
Intents
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”));
Intentsstart new Activity
● Launch another activity
Intent i = new Intent(this, SecondActivity.class)
startActivity(i)
Intent Filter
● Registers components as capable of receiving Intents
● Matches intents to the component (Activity , Service, Receivers)
● Declared mostly in AndroidManifest.xml
Functional Android App
<?xml version="1.0" encoding="utf-8"?><manifest> <uses-permission /> <uses-sdk />
<application> <activity>
</activity> </application></manifest>
Application Manifest File
<?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
Preview
Layouts
• Linear Layout
• Relative Layout
• List View
• Grid View
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>
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>
Layouts
Grid ViewList View
UI Widgets
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);
Sample Apppublic void (View v){
// action }
Add this in XML fileandroid:onClick="myMethod"
Sample App
● Extend this to create SecondActivity● invoked on clicking the button
Inside the APK● Compiled Java source● Libraries ● XML files for UI, strings● Resources – Images etc● Android Manifest
Android Software Stack
● Kernel● Libraries / Runtime● Application Framework● Applications
Android Software Stack
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
Libraries
• A set of C/C++ libraries exposed to developers through the application framework
Application Framework
Application Framework
Applications
Summary
● Android Components● Android Sample Program● Activity, Services, Broadcast Receiver● Intents● Android Stack