Android beginners David

34
ANDROID FOR BEGINNERS

Transcript of Android beginners David

Page 1: Android beginners David

ANDROID FOR BEGINNERS

Page 2: Android beginners David

WHAT IS ANDROID?

Open source OS Uses Linux kernel Optimized for limited-resource environment Apps typically written in Java Apps run on the Dalvik Virtual Machine

Page 3: Android beginners David

ANDROID – NOW

1B users 1.5M new users every day 60 OEM worldwide & 300 partners 50B downloads 2.5B app downloads 2.5 times higher than last year 7x higher revenue

Page 4: Android beginners David

Android Versions

Page 5: Android beginners David

ARCHITECTURE

Page 6: Android beginners David

LINUX KERNEL

Android OS is built on top of the Linux 3.x Kernel This Linux will interact with the hardware and contains

all the essential hardware drivers Drivers are programs that control and communicate with

the hardware For example, consider the Bluetooth function. All devices

has a Bluetooth hardware in it. Therefore the kernel must include a Bluetooth driver to communicate with the Bluetooth hardware.

Page 7: Android beginners David

LIBRARIES

It is this layer that enables the device to handle different types of data.

These libraries are written in C or C++ language and are specific for a particular hardware.

Page 8: Android beginners David

LIBRARIES

SQLite: SQLite is the database engine used in android for data storage purposes.

WebKit: It is the browser engine used to display HTML content.

OpenGL: Used to render 2D or 3D graphics content to the screen

Media framework: Media framework provides different media codecs allowing the recording and playback of different media formats

Page 9: Android beginners David

RUNTIME

DVM is a type of JVM used in android devices to run apps and is optimized for low processing power and low memory environments.

Unlike the JVM, the Dalvik Virtual Machine doesn’t run .class files, instead it runs .dex files.

The Dalvik VM allows multiple instance of Virtual machine to be created simultaneously providing security, isolation, memory management and threading support.

Page 10: Android beginners David

APP FRAMEWORK

These are the blocks that our applications directly interacts with.

These programs manage the basic functions of phone like resource management, voice call management etc.

As a developer, you just consider these are some basic tools with which we are building our applications.

Page 11: Android beginners David

APP FRAMEWORK

Activity Manager: Manages the activity life cycle of applications

Content Providers: Manage the data sharing between applications

Telephony Manager: Manages all voice calls. We use telephony manager if we want to access voice calls in our application.

Location Manager: Location management, using GPS or cell tower.

Page 12: Android beginners David

APPLICATION

Applications are the top layer in the Android architecture and this is where our applications are going to fit.

Several standard applications comes pre-installed with every device, such as:

SMS client app Dialer Web browser Contact manager

Page 13: Android beginners David

PREREQUISITES

Java – JDK

Adt bundle (Eclipse + SDK)

Android Device (optional)

Mobile Drivers for windows

Page 14: Android beginners David

DEMO

Page 15: Android beginners David

COMPONENTS OF ANDROID

Page 16: Android beginners David

ACTIVITY

Activity is an individual user interface screen in an Android application

Visual elements called Views (also known as widgets) can be placed

The user can perform various actions by interacting with it.

Page 17: Android beginners David

POINTS TO REMEMBER

The widgets in an Activity can be created in two different ways, by pure java code and by adding XML code to define the UI.

An application can have more than one Activity and each Activity operates independently, but can be linked to one another and each Activity you create must be defined in your application’s manifest file.

Each Activity in android will be subclass of Activity class defined in Android SDK.

Page 18: Android beginners David

ANDROID PROJECT STRUCTURE /src

The src folder contains the Java source code files of your application organized into packages.

/Android<version Number> The android.jar file contains all the essential libraries

required for our program.

/ASSETS The assets folder is used to store raw asset files. The

raw data can be anything such as audio, video, images etc.

Page 19: Android beginners David

ANDROID PROJECT STRUCTURE

/BIN It is where our compiled application files go. When we

successfully compile an application, this folder will contain java class files, dex files which are executable under Dalvik virtual machine, apk archives etc.

/RES Res folder is where we store all our external resources

for our applications such as images, layout XML files, strings, animations, audio files etc.

Page 20: Android beginners David

ANDROID PROJECT STRUCTURE /res/drawable

The folders are to provide alternative image resources to specific screen configurations. The resources for each screen resolutions are stored in respective folders and the android system will choose it according to the pixel density of the device.

/res/layout XML files that defines the User Interface goes in this

folder. /res/values

XML files that define simple values such as strings, arrays, integers, dimensions, colors, styles etc. are placed in this folder.

Page 21: Android beginners David

ANDROID PROJECT STRUCTURE

Android Manifest file It contains all the information about your application.

When an application is launched, the first file the system seeks is the AndroidManifest file. It actually works as a road map of your application, for the system.

The Android Manifest file contains information about: Components of your application such as Activities,

services etc. User permissions required Minimum level of Android API required

Page 22: Android beginners David

ACTIVITY LIFECYCLE

Page 23: Android beginners David

ACTIVITY LIFECYCLE

Oncreate(Bundle b) : When we launch an Activity in Android, it first calls the

onCreate() method. This is where we do User Interface creation and initialization of data elements. This method is provided with a Bundle object as parameter to restore the UI state.

onStart() : This is called before the Activity is being visible to

the User. Remember that Activity is still not Active.

Page 24: Android beginners David

ACTIVITY LIFECYCLE onResume() : foreground

The Activity become visible and Active for the user to interact with. The Activity will be at the top of the Activity stack at this point. Now the Activity is in running /active state and is able to receive user inputs.

onpause() : background In the Active state, onPause() method will be called when

the system is about to resume another Activity on top of this one or when the user is about to navigate to some other parts of the system.

It gets killed by the system under extremely low memory conditions.

Page 25: Android beginners David

ACTIVITY LIFECYCLE onstop() :

This is the default action when the user has pressed the back button, or a new activity which completely covers it resumes on top.

onDestroy() : This is called and the Activity is destroyed. This is the

final method we can call before the Activity is destroyed. This occurs either because the Activity is finishing the operation or the system is temporarily destroying it to save space.

Page 26: Android beginners David

INTENTS

If you want to invoke a new activity from your current activity, you need to fire an intent specifying the new activity.

And if you want to start other application from your activity, then also you need to fire an intent.

Page 27: Android beginners David

EXPLICIT INTENTS

In explicit Intent, we are highly specific. We specify which activity should get active on receiving the intent.

Intent intent = new Intent(A.this , B.class)startActivity(intent);

Page 28: Android beginners David

IMPLICIT INTENTS In implicit Intent we are sending a message to the

Android system to find a suitable Activity that can respond to the intent.

For example, to open a camera, we can use an intent . If there is more than one activity is capable of receiving the Intent, the system presents a chooser to the user so that he can select which Activity/Application should handle it.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivity(intent);

Page 29: Android beginners David

BROADCAST RECEIVERS

Broadcast receivers are one of Android application components that is used to receive messages that are broadcasted by the Android system or other Android applications.

Example : 1. Warning that the battery is getting low 2. Change of time zone

Page 30: Android beginners David

CONTENT PROVIDERS

Content providers in Android provides a flexible way to make data available across applications. Through content providers other applications are able to query, access or even modify the data you’ve created, as long as your content provider allows it.

Example : The contacts database. The Content provider of contacts

database allows other applications to query, read, modify, and write the contacts info.

Page 31: Android beginners David

SERVICE

A service is an Android application component that run in background and has no visual UI.

A service can be started by another Android application components such as an activity or other services and it will continue to run in the background even after the user switches to another application.

Page 32: Android beginners David

Example : One typical example for the use of services is a music

player application. We can use an activity to select a music track from the SD card and to play it.

At any time the user is able to come back to the activity and use the seek bar to seek the track, This means that the service and the Activity that invoked the service are not completely independent, instead the Activity is able to fully control the Service.

Another example for a service is the downloading of file from the internet. It should run in the background and continue downloading even after we switches to another applications.

Page 33: Android beginners David

GOOGLE STUDENT AMBASSADOR

CommunityCollege events & HackathansTraining & Workshopshttps://plus.google.com/u/0/communities/107158244985901317444

Page 34: Android beginners David

HANDS ON