android-tutorial-for-beginner

27
An android development tutorial for beginners... Ajailal.P Ajailal.P

Upload: ajailal-parackal

Post on 17-May-2015

3.328 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: android-tutorial-for-beginner

An android development tutorial for beginners...

Ajailal.PAjailal.P

Page 2: android-tutorial-for-beginner

MOBILE OS

Symbian iPhone RIM's BlackBerry Window mobile Linux Palm WebOS Samsung BADA OS Android ….

Page 3: android-tutorial-for-beginner

WHAT IS ANDROID?

Google OHA (Open Handset Alliance) The first truly open and comprehensive platform

for mobile devices, all of the software to run a mobile phone but without the proprietary obstacles that have hindered mobile innovation.

Linux OS kernel Java programming Open source libraries: SQLite, WebKit, OpenGL

Page 4: android-tutorial-for-beginner

WHY ANDROID

A simple and powerful SDK No licensing, distribution, or development

fees Development over many platform

Linux, Mac OS, windows Excellent documentation Active developer community

Page 5: android-tutorial-for-beginner

ANDROID SDK FEATURE

Network GSM, EDGE, and 3G networks, WiFi, Bluetooth

Libraries SQLite (lightweight relational DB), WebKit layout

engine coupled with chrome web browser, SSL VGA, 2D graphics library, 3D graphics library based on

OpenGL ES 2.0 specifications, and traditional smart phone layouts.

Hardware control video/still cameras, touch screens, GPS,

accelerometers, gyroscopes, magnetometers, proximity and pressure sensors, thermometers, accelerated 2D and 3D graphics.

Location-based service map (Google API)

Page 6: android-tutorial-for-beginner

ANDROID VERSIONS

1.5 Cupcake1.6 Donut2.0/2.1 Éclair2.2 Froyo2.3 Gingerbread3.0 Honeycomb

Page 7: android-tutorial-for-beginner

TOOLS The Android Emulator

Implementation of the Android virtual machine Test and debug your android applications.

Dalvik Debug Monitoring Service (DDMS) Monitor and Control the Dalvik virtual machines Logcat (see logged msgs)

Android Debug Bridge (ADB) Manage the state of an emulator instance or Android-

powered device Copy files, install compiled application packages, and run

shell commands. TraceView

Graphical analysis tool for viewing the trace logs from your Android application

Debug your application and profile its performance MkSDCard

Creates an SD Card disk image

Page 8: android-tutorial-for-beginner

ANDROID APPLICATION ARCHITECTURE

Views: Building block for user interface components.

Activities A single, focused thing that the user can do. Interaction with users: creating a window to

place UI

Page 9: android-tutorial-for-beginner

ANDROID APPLICATION ARCHITECTURE

Services (Background) Ex: Network Operation

Intent Inter-communication among activities or services

Resource Externalization of strings and graphics

Notification signaling users: Light, sound, icon, dialog,

notification Ex: new message arrives

Content Providers share data between applications

Intent

Page 10: android-tutorial-for-beginner

VIEW Layout of visual interface

Java Code Initialize

Access TextView myTextView =

(TextView)findViewById(R.id.myTextView);

<?xml version=”1.0” encoding=”utf-8”?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent”><TextView android:id=”@+id/myTextView” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”Hello World, HelloWorld”/></LinearLayout>

@Overridepublic void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.screen);}

screen.xml

Page 11: android-tutorial-for-beginner

VIEW COMPONENT

Widget Toolbox TextView, EditText,Button, Form, TimePicker… ListView Layout

To positions of controls LinearLayout, Relativelayout,

Menu ex. Exit, Settings etc

Page 12: android-tutorial-for-beginner

ACTIVITY

A single, focused thing that the user can do. Activities are like a stack. So when we call startActivity(), we are telling Android "put this activity on top of mine”

Foreground Activity: suspended when invisible Visual, interactive Ex: Game, Map

Background Service: Little interaction Ex: Hardware, power management

Intermittent Activity Notification

Page 13: android-tutorial-for-beginner

Activity lifecycle

Page 14: android-tutorial-for-beginner

USER INTERACTION EVENT onKeyDown, onKeyUp onTrackBallEvent onTouchEvent

myEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { … return true; } return false; }});}

registerButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {….}}

Page 15: android-tutorial-for-beginner

INTENT

An intent is an abstract description of an operation to be performed. Launch an activity

Explicit

Implicit: Android selects the best startActivity();

Subactivity: feedback Child: use intent as feedback, setResult ( before

finish() ) Parent: onActivityResult startActivityForResult

Action, data, extra parameter intent.putExtra(name, property);

Ex: Intent intent = new Intent(MyActivity.this, MyOtherActivity.class);

Page 16: android-tutorial-for-beginner

SERVICE Service class

public class MyService extends Service public void onStart() {…}

Manifest.xml <service android:enabled=”true”

android:name=”.MyService”></service>

Control startService stopService

Communication Bind service with activity: use public method and

properties Intent

Page 17: android-tutorial-for-beginner

WORKING IN BACKGROUND

Services NO GUI, higher priority than inactive Activities Usage:

responding to events, polling for data, updating Content Providers.

However, all in the main thread

Background threads

Page 18: android-tutorial-for-beginner

THREADING

What to thread? Network, file IO, Complex processing

How ? new Thread Synchronize threads

Handler.post()

UI Thread ( AsyncTask ) doInBackground() onPreExecute() onProgressUpdate() onCancelled() onPostExecute()

Page 19: android-tutorial-for-beginner

EXTERNAL RESOURCES values/

String, color, array, dimension, style theme drawables/

Images, icon layout/

main.xml Menu

menu.xml

There can be separate layout and drawables folders for landscape and portrait orientation.

There can be different layout and drawables folders for small, large and normal screen. And hdpi, mdpi, ldpi resolutions.

Page 20: android-tutorial-for-beginner

SERVICE APP – MANIFEST.XML

Service

Activity (intent-filter)

Permission

Page 21: android-tutorial-for-beginner

Application

Activity 1 (main)

Activity 2

SDK Version

Screen Support

NORMAL APPLICATION – MANIFEST.XML

Page 22: android-tutorial-for-beginner

DEBUG

Package - android.util.Log

View results Logcat Eclipse IDE

Page 23: android-tutorial-for-beginner

DEBUG ON DEVICE

On device Debug mode

On desktop Connect your Phone with your PC When it asks for driver location choose

For windows, android-sdk-windows-1.5_r3\usb_driver\x86\

You'll see sth like "HTC Dream Composite ADB Interface" on success

(Re)Start Eclipse Your G1 should now be listed in the DDMS-

Perspective under Device

Page 24: android-tutorial-for-beginner

INSTALL PACKAGE TO ANDROID PHONES

Compile the apk packages in Eclipse Export signed application package

adb install …apk Error: uninstall

Page 25: android-tutorial-for-beginner

DALVIK DEBUG MONITORING SERVICE

Page 26: android-tutorial-for-beginner

ANDROID DEBUG BRIDGE (ADB)

Page 27: android-tutorial-for-beginner