You are on page 1of 15

Search...

Search

Tutorials

Reviews

Interviews

Tools

News

Giveaways

Resources

Tips

Subscribe to RSS

Mobile App Source Code


www.chupamobile.com Buy and sell Mobile App source code for Mobile Development

Introduction to Android App Development


by MINA SA MY on 1 0 . NOV , 2 0 1 0 in A NDROID, T UT ORIA LS

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


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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

B. C/C++ Libraries: such as SQL lite, Graphics libraries OpenGL ES, media framework and webkit layout engine. C. The Android Runtime : includes Core libraries and the 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 multiple instances of VMs. As Java applications access the core libraries each application has its own VM D. The Android Application Framework: Provides classes required to develop an Android application and abstraction between hardware access. the Android Java APIs main library include telephony, content providers (data), resources, locations and UI. E. Application Layer : all Android applications(native or third party) are built on the application layer using the same API. So Android applications are written in Java, but remember it is not Java ME (Mobile Edition). Its just Most of J2SE libraries + Androids own Java libraries.
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

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 enables developers to include out of the box components such as the phone dialer or contact manager to their 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 to the windows or web forms they carry the controls (views) that construct the interface, an activity represents a single screen. Views: the UI components that construct the interface. They can be compared to the swing or windows forms controls

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 to store resources such as strings or images.

Android Versions:
Android has been updated many times since its release, these updates were to fix bugs and add new 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 SDK C. Eclipse IDE . D. Follow the installation links from this link. After youre done you will be ready to start developing Android Applications.

Our First Android Application:


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

pdfcrowd.com

Now were going to explore our first Android application which will be the famous Hello World application. We are going to explain the structure of an Android application and some of the basic concepts we must understand.

A. Open Eclipse and select from the menu File>New> Project, youll see a window like this from 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 project files. 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 avoid applications package name conflict is com.mydomain.myapp. Create Activity: the name of the basic activity class of your application. its optional to create. Min SDK Version: the minimum API level required by the application. You see in the Build Target list there is a list of the available SDK versions to use for the application and in front of each one the corresponding API level. You must ensure that you application API level is supported by the device select it to be 8 (for Android 2.2).

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

C. Press next; we wont 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 that holds a reference to each resource in the application Android 2.2: Its name changes according to the sdk version you use (2.2 here). Contains the Android API class files packed in android.jar files Assets: You can place any external resources (text files, images,) in this folder. Its much

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

like the res file except its more like the file system where you put files that you want to access them as raw bytes Drawable folders: Contains the images required for you application. You can add your own image 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 the different phone screens. And at runtime Android will pick the suitable image from the suitable folder. Layout: Contains the main.xml file that defines the view that construct the User Interface of the application Values: Contains other resources that can be used for your application such as string resources, styles or colors Now were going to take a deeper look on the Hello Android application and know what each line of code exactly means The 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);

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

} } 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.Bundle C. 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 web forms. D. Our class contains one function which is onCreate(Bundle savedInstanceState). This function is called when the activity is first created, it should contain all the initialization and UI setup. This function has a parameter savedInstanceState of type Bundle this object holds the activitys previously saved state if exists (similar to asp.net view state concept) E. Line 10 calls the super class OnCreateMethod with the activitys F. 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 class This method is required to display the user interface, if the activity does not include this function 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" /> open in browser PRO version
Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

</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 a string 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 the TextView 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:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 file and 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 layout view by pressing the layout tab in the main.xml file and choose the views from the toolbox.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 UI defined 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 on Android app development.

Similar articles: Simple develops Android app with Two Toasters INFOGRAPHIC: Top 32 Resources A Mobile App Developer Should Know About WIN: 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 next post

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 #


Thanks Im 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 #


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

pdfcrowd.com

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 available anywhere? I would love to do the tutorials, but I really dont want to type in every bit of code. Thanks, Jerry
REPLY

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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.com but sorry for the rest, youll have to copy/paste it. thanks
REPLY

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


Good postlooking forward to more.
REPLY

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


Great post on Android Development..Looking forward to reading the rest of your blog.
REPLY

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


awesome kickstart
REPLY

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Trackbacks/Pingbacks
1. Android Entwicklung | medienproduzent.net [...] Introduction to Android development [...] 2. Weekly Design News Resources, Tutorials and Freebies (N.64) | Android [...] Introduction to Android development [...] 3. Introduction to the Android Development World | What Is Android 16. Oct, 2011 20. Nov, 2010 10. Nov, 2010

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

Leave a Reply
Name Mail (w ill not be published) (Required) Website

Submit Comment

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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

Project Mgmt Software


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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You might also like