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
15
Embed
Mobileorchard Com Introduction to Android Development
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
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
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.
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).
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
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:
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:
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:
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.
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
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.
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 [...]