+ All Categories
Home > Documents > Mobileorchard Com Introduction to Android Development

Mobileorchard Com Introduction to Android Development

Date post: 23-Oct-2015
Category:
Upload: omprakkash1509
View: 6 times
Download: 1 times
Share this document with a friend
Description:
snap pdf
Popular Tags:
15
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API Search... Subscribe to RSS Search Mobile App Source Code www.chupamobile.com Buy and sell Mobile App source code for Mobile Development by MINA SAMY on 10. NOV, 2010 in ANDROID, TUTORIALS Welcome to the first Android development articles on Mobile Orchard. We are going to start a series of articles to introduce you to the world of Android development. We are going to start off with the Android platform and the necessary tools to start Android development. Android Software Stack: This picture describes the Android software stack that can be described as a Linux Kernel and C/C++ libraries exposed through an application framework that provides services for and management of runtime and applications. The elements of the Android software stack are: A. Linux Kernel: provides abstraction between the hardware and the rest of the stack, responsible for device drivers (Camera , Wi Fi, etc…), resources management , power management, security and net working SPONSORED APPS Living Earth HD by Radiantlabs, LLC Advertise your app here Introduction to Android App Development Tutorials Reviews Interviews Tools News Giveaways Resources Tips
Transcript
Page 1: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Search...

Subscribe to RSS

Search

Mobile App Source Codewww.chupamobile.com

Buy and sell Mobile App source code for Mobile Development

by MINA SA MY on 1 0. NOV , 2 01 0 in A NDROID, TUTORIA LS

Welcome to the first Android development articles on Mobile Orchard. We are going to start aseries of articles to introduce you to the world of Android development. We are going to start offwith the Android platform and the necessary tools to start Android development.

Android Software Stack:

This picture describes the Android software stack that can be described as a Linux Kernel andC/C++ libraries exposed through an application framework that provides services for andmanagement of runtime and applications.

The elements of the Android software stack are:

A. Linux Kernel: provides abstraction between thehardware and the rest of the stack, responsible fordevice drivers (Camera , Wi Fi, etc…), resourcesmanagement , power management, security and networking

SPONSORED APPS

Living Earth HDby Radiantlabs, LLC

A dv er t ise y ou r a pp h er e

Introduction to Android App Development

Tutorials Reviews Interviews Tools News Giveaways Resources Tips

Page 2: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

B. C/C++ Libraries: such as SQL lite, Graphics librariesOpenGL ES, media framework and webkit layoutengine.

C. The Android Runtime : includes Core libraries andthe Dalvik Vitual Machine.The Core libraries provide most of java libraries + additional Android libraries.The Dalvik VM provides (Just In Time) JIT compilation. the VM is optimized to run multipleinstances of VMs. As Java applications access the core libraries each application has its ownVM

D. The Android Application Framework: Provides classes required to develop an Androidapplication and abstraction between hardware access. the Android Java API’s main libraryinclude telephony, content providers (data), resources, locations and UI.

E. Application Layer: all Android applications(native or third party) are built on the applicationlayer using the same API.

So Android applications are written in Java, but remember it is not Java ME (Mobile Edition). It’sjust Most of J2SE libraries + Android’s own Java libraries.

The Android Application structure:

Android architecture encourages component reuse allowing you to publish and share activities,services and data between applications with security restrictions defined by you. This enablesdevelopers to include out of the box components such as the phone dialer or contact manager totheir applications, or add new functionalities to them.

The bases of the Android applications are:

Activity Manager: which controls the life cycle of the activities, activities can be compared tothe windows or web forms they carry the controls (views) that construct the interface, anactivity represents a single screen.Views: the UI components that construct the interface. They can be compared to the swing orwindows forms controls

POPULAR POSTS

Android App Development:Threading part 1:Handlers

Tutorial: JSON Over HTTP On The iPhone

Tutorial: Networking and Bonjour on iPhone

7 UI Design Resources for iPhone Developers

iOS Development Tutorial Series: Hello World

Page 3: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Notification Manger: provides a consistent mechanism to notify or alert users.Content Providers: lets applications to share data between them.Resources Manager: much like the ASP.NET resources concept. Enables the developer tostore resources such as strings or images.

Android Versions:

Android has been updated many times since its release, these updates were to fix bugs and addnew functionalities. Each Android update has a name of a dessert.

Android 1.5 (Cup Cake).Android 1.6 (Donut).Android 2.0/2.1 (Eclair).Android 2.2 (Froyo).Android 2.3 (Gingerbread).

Getting started with Android development tools:

Android applications can be developed on Windows, Mac or Linux platforms.

To start developing Android apps you need:

A. Download and install the Java Development Kit (JDK).B. The Android SDKC. Eclipse IDE .D. Follow the installation links from this link.

After you’re done you will be ready to start developing Android Applications.

Our First Android Application:

Page 4: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Now we’re going to explore our first Android application which will be the famous Hello Worldapplication. We are going to explain the structure of an Android application and some of the basicconcepts we must understand.

A. Open Eclipse and select from the menu File>New> Project, you’ll see a window like thisfrom the Android node select Android project and press Next.

B. Now there are several fields that appear here they are:Project Name : The Eclipse project name, the name of the folder that will hold the projectfiles.Application Name :The name of the application that will appear on the phone.Package Name : The application package name, a good convention to use to avoidapplications package name conflict is com.mydomain.myapp.Create Activity: the name of the basic activity class of your application. it’s optional tocreate.Min SDK Version: the minimum API level required by the application. You see in the BuildTarget list there is a list of the available SDK versions to use for the application and in front ofeach one the corresponding API level. You must ensure that you application API level issupported by the device select it to be 8 (for Android 2.2).

Page 5: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

C. Press next; we won’t create a test project for our application yet.D. Press Finish then navigate to the project press run and choose run as Android Application,

the emulator will start, wait until the main screen appears.

The Android Emulator may take some time, so please be patient. After the emulator launches,unlock it and your application will launch automatically. it should be like this:

Android Project Structure:

The project contains the following folders:

Src: Contains all the source code (class files) for the project.Gen: Contains the R.java class file. The R.java is an automatically generated class file thatholds a reference to each resource in the applicationAndroid 2.2: Its name changes according to the sdk version you use (2.2 here). Contains theAndroid API class files packed in android.jar filesAssets: You can place any external resources (text files, images,…) in this folder. It’s much

Page 6: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

like the res file except it’s more like the file system where you put files that you want to accessthem as raw bytesDrawable folders: Contains the images required for you application. You can add your ownimage files to this folder. Notice that there are three folders with hdpi,ldpi and mdpi suffixes.These folders are used to include image resources with different resolutions suitable to thedifferent phone screens. And at runtime Android will pick the suitable image from the suitablefolder.Layout: Contains the main.xml file that defines the view that construct the User Interface ofthe applicationValues: Contains other resources that can be used for your application such as stringresources, styles or colors

Now we’re going to take a deeper look on the Hello Android application and know what each line ofcode exactly meansThe MainActivity.java file contains the following code:

package mina.android.hellowolrd;

import android.app.Activity;

import android.os.Bundle;

public class MainActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Page 7: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

}

}

A. The first line is the package name of the application.B. Lines 3,4 are import statements of two libraries(): android.app.Activity and android.os.BundleC. Line 6 is the declaration of the MainActivity class which extends from Activity , Activity

represents the User interface view or window of your application much like windows or webforms.

D. Our class contains one function which is onCreate(Bundle savedInstanceState). This functionis called when the activity is first created, it should contain all the initialization and UI setup.This function has a parameter savedInstanceState of type Bundlethis object holds the activity’s previously saved state if exists (similar to asp.net view stateconcept)

E. Line 10 calls the super class’ OnCreateMethod with the activity’sF. Line 11 calls setContentView(R.layout.main); method which dsiplays the layout definition in

main.xml file in res/layout directory by accessing a reference to it from the R classThis method is required to display the user interface, if the activity does not include thisfunction then it would display a blank screen.

If we went to main.xml in the layout folder we will find it like this:

<?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"

/>

Page 8: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

</LinearLayout>

This xml layout file defines a vertical LinearLayout Container with a TextView inside it.

The TextView has a text property android:text=”@string/hello”. This means that there is astring resource called hello is defined in the values/strings.xml with the value “Hello World,MainActivity!”.

What if we want to reference this TextView from our class, we will add an id property to theTextView to be like this:

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:id="@+id/txtHello"

/>

The id of any view in Android must be in this format “@+id/(id of the view)”

After we added the id property to the view, we reference it from the code like this:

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextView txt=(TextView)findViewById(R.id.txtHello);

txt.setText("referenced from code");

}

Run the application it should be like this:

Page 9: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Notice that we reference our TextView with the method findViewById(int Id).

The id of the TextView (txtHello) is strongly typed as it was added automatically to the R.java fileand assigned an integer value:

public final class R {

public static final class attr {

}

public static final class drawable {

public static final int icon=0x7f020000;

}

public static final class id {

public static final int txtHello=0x7f050000;

}

public static final class layout {

public static final int main=0x7f030000;

}

public static final class string {

public static final int app_name=0x7f040001;

public static final int hello=0x7f040000;

}

}

Note:

You do not to add views (controls) to your activity in the xml directly. You can switch to the layoutview by pressing the layout tab in the main.xml file and choose the views from the toolbox.

Page 10: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

There is also a nice UI generator tool called Droid Draw.

Summary:The basic Android application with only one view consists of a class that extends the Activity class.This class preserves the activity frozen state (like viewstate in asp.net) and it displays the UIdefined in xml file layout file or defined explicitly programmatically.

We hope you found this tutorial informative and look forward to bringing you our new series onAndroid app development.

Similar articles:

Simple develops Android app with Two ToastersINFOGRAPHIC: Top 32 Resources A Mobile App Developer Should Know AboutWIN: Top Android titles from Pearson!!!Win copies of Top selling Android books

15 Responses to “Introduction to Android App Development”

Dee 10. Nov, 2010 at 5:02 pm #

Excellent start to the android development series Mina.. lookin’ forward to the nextpost

Page 11: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

I just got an android phone and was playing with developing some widgets for personal use.

Dee

REPLY

Mina Samy 11. Nov, 2010 at 1:26 am #

ThanksI’m glad you liked it, Developing for Android is really interesting.

REPLY

Frank 13. Nov, 2010 at 6:07 am #

Really nice intro to Android development. Good work Mina.

Do you plan to run a series?

REPLY

Mina Samy 13. Nov, 2010 at 1:09 pm #

Sure Frank, there gonna be more Android Dev articles

REPLY

Can 19. Nov, 2010 at 7:37 pm #

Page 12: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Nice post thank you. Will help me much

REPLY

Brett Widmann 26. Feb, 2011 at 7:30 pm #

App development is HUGE! Thanks for this helpful article.

REPLY

Supriya 06. Apr, 2011 at 1:16 am #

Very helpful post..thanks a lot….

REPLY

JerryH 25. Jun, 2011 at 4:34 pm #

Mina, Is the source code for your Mobile Orchard android tutorials availableanywhere?

I would love to do the tutorials, but I really don’t want to type in every bit of code.

Thanks,Jerry

REPLY

Page 13: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Mina 27. Jun, 2011 at 4:42 am #

Hi Jerry, you can find some source code on some topics in my personal blog: http://android-pro.blogspot.combut sorry for the rest, you’ll have to copy/paste it.thanks

REPLY

Mark Turkel 14. Nov, 2011 at 12:32 pm #

Good post…looking forward to more.

REPLY

Alex Design 05. Feb, 2012 at 2:26 pm #

Great post on Android Development…..Looking forward to reading the rest ofyour blog.

REPLY

sai madan 04. Feb, 2013 at 12:35 pm #

awesome kickstart

REPLY

Page 14: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

Leave a Reply

Name

Mail (w ill not be published) (Required)

Website

Trackbacks/Pingbacks

1. Android Entwicklung | medienproduzent.net - 10. Nov, 2010

[...] Introduction to Android development [...]

2. Weekly Design News – Resources, Tutorials and Freebies (N.64) | Android - 20. Nov, 2010

[...] Introduction to Android development [...]

3. Introduction to the Android Development World | What Is Android - 16. Oct, 2011

[...] We are going to start a series of articles to introduce you to the world of Androiddevelopment.Read MoreIntroduction to Android Development Mobiletuts iPhoneThis article willintroduce you to the Android [...]

Submit Comment

Page 15: Mobileorchard Com Introduction to Android Development

pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

© 2008-2051 • Mobile Orchard and the Bar-Tree Logo are service marks. Contact • Advertise

Project Mgmt Softwarequickbase.intuit.com

Try it Free for 30 Days- Start Now! Automate Business Processes & More.


Recommended