Creating an Application

Creating an Android application with Android Studio is as easy as a few mouse clicks. This section shows how to create a Hello World application, package it, and run it on the emulator. Make sure you have installed the Android SDK and Android Studio by following the instructions in the previous section.

If you cannot run Android Studio because it is looking for the JDK in the wrong place, click File > Project Structure > SDK Location, and then browse to the location of the JDK.

To create an application, follow these steps:

Android Studio has a nice little step-by-step tool to help you create your project. Click Start a new Android Studio Project from the Welcome to Android Studio screen:

Screen Shot 2015-11-08 at 8.19.39 PM

Note: If you currently have an Android Studio project open and can’t see the welcome screen, select File\New Project from the menu to create a new project.

Identify Your Project

Android Studio will present you with a project creation screen:

Screen Shot 2015-11-08 at 8.20.43 PM

Enter OMG Android in Application name as shown above.

Feel free to put your own name in the Company Domain text field. As you type, you’ll notice the Package Name automatically changes to create a reverse domain style name based on your entries.

The Package Name is used to uniquely identify your app so that any work performed by a device is always properly attributed to the source, thus preventing confusion between apps.

You can set the Project location to any location on your hard drive — keep the default if you don’t have a preference. Click Next at the bottom of the window.

Choose an SDK

The next screen is the Target Android Devices window. This is where you select device types and operating systems to target.

The Minimum SDK drop-down menu sets the minimum version of Android required to run your app. The newer the SDK, the more features you’ll have at your disposal; however, newer SDKs support fewer devices.

Selecting this value is simply a matter of balancing the capabilities you want and the devices you want to support. This is where developing for Android can get a little tricky.

If you really want to get into the details of what Minimum SDK version is best for your App, let Android Studio help you out.

As you change the Minimum SDK in the drop down menu, the percentage in the text underneath reflects what percentage of devices currently run that version of Android.

Click Help me choose underneath the drop down list to learn more about each SDK’s set of features.

Screen Shot 2015-11-08 at 8.22.04 PM

For more information on API versions and their uses, check out the Android Dashboards, which are updated every few days.

android_dashboard_1

For now, you just want an App that works on an Android Phone, and that is what you’ll see by default, alongside the default Minimum SDK. For this project, select SDK of API 16: Android 4.1 (Jelly Bean).

Screen Shot 2015-11-08 at 8.21.07 PM

Set the Default Activity

After you choose the SDK, you choose a default activity for your app.

Screen Shot 2015-11-08 at 8.22.35 PM

Activity  — a window within your app that displays content with which the user can interact.

An activity can take up the entire screen or it could be a simple pop-up.

Your options on this particular template range from a blank activity with an Action Bar right up to an Activity with an embedded MapView.

You’ll make a lot of activities as you develop apps, so get to know them and know them well.

Select the Blank Activity option and click Next.

Screen Shot 2015-11-08 at 8.22.54 PM

To speed this part up a little bit you’ll use the pre-populated default values, but what is actually done with these values?

  • Activity Name: This gives your activity a name to refer to in code.
    • A .java class will be created and will use the contents of this text field to give the class a name, which will ultimately be the name you use to refer to this activity in your code.
  • Layout Name: You’re going to define your activity in Java, but the layout it shows to the user is defined in a special sort of Android XML.

Click Finish.

Android Studio takes this as a cue to go do a bunch of behind-the-scenes operations and create your project.

After a brief moment, Android Studio will finish building your project. The project is pretty empty, of course, but it has everything it needs set up so that it can be launched on an Android device or emulator. You’ll be dropped off in this spot:

Screen Shot 2015-11-08 at 8.25.52 PM

And that’s all it takes to create a Hello World project on Android Studio! Now to dress it up and work through building and running this project on an emulator.