Professional Documents
Culture Documents
Search
Tutorials
Reviews
Interviews
Tools
News
Giveaways
Resources
Tips
Subscribe to RSS
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.
SPONSORED APPS
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
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).
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).
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:
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);
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:
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.
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
Excellent start to the android development series Mina.. lookin forward to the next post
pdfcrowd.com
I just got an android phone and was playing with developing some widgets for personal use. Dee
REPLY
pdfcrowd.com
pdfcrowd.com
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
pdfcrowd.com
2008-2051 Mobile Orchard and the Bar-Tree Logo are service marks. Contact Advertise
pdfcrowd.com