Vous êtes sur la page 1sur 11

Android Basics

Getting started to Android Development

Agenda
First things first Creating your first Activity Android Basic Building Blocks Important Building Blocks Understanding Hello Android Demonstration.

First things first

Android SDK 1.0_r2 at http://code.google.com/android/


ofcourse we need JDK 5 or later

First things first


Get Eclipse with ADT plug -in (other IDE is also applicable)
1. Select Help > Software Updates > Find and Install from within Eclipse. 2. In the resulting dialog box, choose Search for new features to install. 3. Select New Remote Site, and enter the following address into the dialog box: https://dl-ssl.google.com/android/eclipse/ 4. The new site you entered should now be checked. Click Finish. 5. Eclipse will now download the plug-in. When its fi nished, select Android Plugin > Developer Tools from the resulting Search Results dialog box, and click Next. 6. Read and then Accept the terms of the license agreement, and click Next and then Finish. As the ADT plug-in is not signed, youll be prompted before the installation continues. 7. When complete, youll have to restart Eclipse and update the ADT preferences. Restart and select Window Preferences (or Eclipse > Preferences for the Mac OS). 8. Then select Android from the left panel. 9. Click Browse , and navigate to the folder into which you unzipped the Android SDK, as shown in Figure 2-3; then click Apply and OK.

Creating your first Android Activity


Just like your normal Eclipse Project except that we are now creating a project for Android.

Android Basic Building Blocks


Activities - UI component typically corresponding to one screen.
Android uses a special class called an Intent to move from screen to screen. An intent describes what an application wants done. There is a related class called an IntentFilter. It is a description of what intents an activity (or BroadcastReceiver, see below) is capable of handling. Broadcast Intent Receiver- a way to respond to an external event like notifications or alarm. Services Faceless tasks that run in the background. Content Providers Enable applications to share data.

Important Building Blocks


VIEWS are also known as widgets, gui components , can be basic, fancier and customized in Android. LAYOUT Controls how views are being laid out : FrameLayout : each child a layer LinearLayout : single row or column RelativeLayout : relative to other Views TableLayout : rows and columns AbsoluteLayout : <x,y> coordinates and they have LAYOUT Parameters specifies many aspects of what is being rendered. RESOURCES - res/layout: declarative layout files res/drawable: intended for drawing res/anim: bitmaps, animations for transitions res/values: externalized values for things like strings, colors, styles, etc. res/xml: general XML files used at runtime res/raw: binary files (e.g. Sound) NOTIFICATIONS - A Notification is a small icon that appears in the status bar. Users can interact with this icon to receive information. AndroidManifest.xml - file is the control file that tells the system what to do with all the top-level components you've created. For instance, this is the "glue" that actually specifies which Intents your Activities receive.

Understanding Hello Android - Activity


import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

Understanding Hello Android Layout XML


<?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:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>

Understanding Hello Android AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="hk.com.novare"android:versionCode="1"android:versionName="1.0.0"> <application android:icon="@drawable/icon"android:label="@string/app_name"> <activity android:name=".HelloAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

Demonstration
Simple CurrencyConverter

Vous aimerez peut-être aussi