Advertisement

Creating Android Hello World Applications

Student iconAre you a student? Get a yearly Tuts+ subscription for $45 →
This post is part of a series called Learn Android SDK Development From Scratch.
Android Sample Apps
Android App Debugging

Recent changes to the Android SDK tools have made it possible to quickly create Android projects using various starting templates. Learn how to create several different "Hello World" apps for the Android platform in this tutorial.


Part 0: Getting Started

This series of Android tutorials is meant to help you build the skills and confidence necessary to build real, quality Android apps. This tutorial is for the Java developer just getting started learning Android app development, who is somewhat familiar with Eclipse and has installed the Android SDK and the Android Developer Plugin for Eclipse. If you are not prepared, see the previous tutorials in this series.


Part 1: Creating a Basic Hello World

First, let's create a classical hello world app that simply draws the text "Hello World" on the screen.


Step 1: Create a New Android Project

In Eclipse, click on the Create New Android Project button.

You can also go to File, New, Other, Android, Android Application Project.


Step 2: Configure the Project Settings

Enter the application name, project name, and package name. Choose a Build SDK that suits your test devices and favored emulator configurations.


Step 3: Add an App Launcher Icon

Click Next. Choose your launcher icon. You can always change it later, but this is for a Hello World app.


Step 4: Select the App Activity Type

Click Next. Now choose "BlankActivity."


Step 5: Specify Activity Details

Click Next. Enter in some details for the Activity. Finally, click Finish.


Step 6: Review Your Simple App

Create an AVD as well as a Run or Debug configuration for you project. Now, run your new project in an emulator or on a compatible Android device. You have now created a simple Android application with one Activity class, one screen, that displays the text Hello world!


Part 2: Creating a Navigable Hello World

Now let's create another Hello World app. This time, follow the steps above, but with changes to Step 2 and Step 5, as outlined below.


New Step 2: Configure The Project Settings

Enter the application name, project name, and package name as you normally would. However this time you must set your project’s "Minimum Required SDK" value to"API 14: Android 4.0 (IceCreamSandwich)". This means the application you create will only be compatible with devices and emulators running Android 4.x and higher (API Level 14).


New Step 5: Specify Activity Details

Now choose something other than "None" for navigation type. The options available are Tabs, Tabs + Swipe, Swipe Views + Title Strip, and Dropdown. A little hint graphic is shown to the right to give you an idea what each means. For this example, we have chosen the Swipe Views + Title Strip navigation type. Finally, click Finish.


New Step 6: Review Your Navigable App

Create an AVD as well as a Run or Debug configuration for you project. Now, run your new project in an emulator or on a compatible Android device. You have now created a more interesting hello world Android application with enhanced navigation options!


Part 3:
Creating a Fragmented Hello World

Now let’s create a classical fragment-based hello world app that displays a list in one fragment with the details in another fragment. This will display as two screens on a portrait-mode standard display or using a split-pane design on a landscape tablet sized display. Again, we will only list the steps when they differ from the previous examples.


New Step 2: Configure The Project Settings

The application must have a Minimum Required SDK value of "API 11: Android 3.0 (Honeycomb)" in order to use the fragments as the Eclipse Android project wizard doesn't take advantage of tools like the Android Support library, which back-ports technologies like fragments to older versions of the Android platform.


New Step 4: Select the App Activity Type

This time, instead of BlankActivity choose MasterDetailFlow on the Create Activity screen.

Click Next and then fill in the details for the Master/Detail flow. For the purposes of this tutorial, we will be working with a set of “Things”.


New Step 6:
Review Your Fragment-Aware App

Create an AVD as well as a Run or Debug configuration for you project. Now, run your new project in an emulator or on a compatible Android device. You have now created a more interesting hello world Android application with a fragment-based design!

When you run this Hello World, the resulting display will be different depending upon the type of device or emulator you run it on and its screen orientation. Here is the app as displayed on a regular, small screen emulator.

And here's the same app running on a higher resolution and landscape emulator with tablet screen dimensions.


Conclusion

You've now learned how to create a variety of different "Hello World," style apps. These include basic blank screens, apps with different types of navigation, and more complex apps that are fragment-aware. Using the Eclipse Android project wizard can help get you started quickly and in the right direction. You're just about ready to begin learning Android development!

You're well on your way to Android development. What kinds of apps are you looking forward to creating? Which sample app was your favorite? Let us know in the comments!

About the Authors

Mobile developers Lauren Darcey and Shane Conder have coauthored several books on Android development: an in-depth programming book entitled Android Wireless Application Development (now in it's third edition as a two-volume set), Sams Teach Yourself Android Application Development in 24 Hours, and Learning Android Application Programming for the Kindle Fire: A Hands-On Guide to Building Your First Android Application. When not writing, they spend their time developing mobile software at their company and providing consulting services. They can be reached at via email to androidwirelessdev+mt@gmail.com, via their blog at androidbook.blogspot.com, and on Twitter @androidwireless.

Need More Help Writing Android Apps? Check out our Latest Books and Resources!

Buy Android Wireless Application Development, 3rd Edition, Volume 1  Buy Sam's Teach Yourself Android Application Development in 24 Hours, 2nd Edition  Mamlambo code at Code Canyon

Advertisement