Skip to content

Creating and Running first Android app

To start working on our very first Android App projects you need android SDK and an IDE. As long as you have android SDK and an IDE which can be configured to work with that SDK you are good to go. The two most used IDEs are Eclipse with ADT bundle which was officially supported IDE for long time. But since the inception of Android Studio it has replaced the eclipse as official IDE for android development. This entire series will assume the use of Android Studio for working for android project. Android Studio can be downloaded from Android Developer website via https://developer.android.com/sdk/index.html.

This tutorial is only for Android Studio all the following tutorials after this one will be generic. Other posts will contain information regarding android development which can be used on any IDE of your preference. If something is Android Studio dependent you’ll be notified before handed.

If not already installed please install Android Studio before continuing further in this post!

Assuming Android Studio is downloaded and Installed correctly, Let’s Create our very first Android App.

Creating Android Studio Project

Creating an android project on Android Studio is very straight forward. You launch the Android Studio, click on new android project then give it some name and feed some required information and your ready to launch you very first android application.

Lets check the details step by step.

Step 1: Launch Android Studio and you’ll be welcomed by a welcome screen after splash screen is finished.

Android Studio Welcome Page
Android Studio Welcome Page

Step 2: Click “Start a new Android Studio project” inside quick start category to create a new project inside android studio or just click on the project name (if already created) inside recent projects category.

New Project Wizard
New Project Wizard

Step 3: Now assuming this is the very first launch of Android Studio and you started a new project, you’ll see the create new project wizard. Give the project some name, in my case it’s “MyApplication” and give your domain name and then click next.

Step 4: Next you’ll arrive at “Target Android Devices” page. This page tells which android api level or android version your application will support.

The minimum api level you’ll select the wider android device versions will be supported by the app but the lower or more complex the feature implementation will be. As Android progresses, with each new version of android release a new android api gets released. Each newer api has more added functionality or better functionality. So if you want to support the latest android phones with all the greatest features android can support you should select higher api level. But the problem is the lower volume of audience you will receive.

For example, you select API Android-22, you’ll be supporting all the android versions after and including Android Lollipop and you can use all the new features Lollipop api has. If you want to add support for Android TV, Wear or Glass this can be done from here also. But this tutorial is just for Phones and Tablets lets just keep it checked and rest unchecked.

New Project Wizard - Target Devices
New Project Wizard – Target Devices

Step 5: After selecting the API level just click next and you’ll see “Add an Activity to Mobile” page. This page lets you add a default activity to the Android Application. but for now just select “Add no Activity”. We’ll add activity manually later. Selecting “Add no Activity” will enable finish button, click it and you are done.

New Project Wizard - Activity Chooser
New Project Wizard – Activity Chooser

Now with the above 5 steps you have set up your very first Android project in Android Studio. Now your Android Studio should be looking something like this.

Newly Created Project
Newly Created Project

Now before launching your first app onto an android device/virtual device we should add an Activity to the project. For brief introduction on Activity, go through my previous post Android: An Introduction. We will discuss about it in much detail later.

To create an activity, first we need to create a java class that should extend Activity class to get all the features and properties of an Activity to show those things onto the screen. To add a new class to your project expand project explorer from the left then go all the way to the App package.

Android Project Explorer
Android Project Explorer

Now right-click on it, select new then select “Java Class”. After this, You’ll see a pop-up asking class name, give it a name like “MainActivity” and click “OK”.

New Class dialog
New Class dialog

Now your new class is added to your project’s package. The only thing left to do with this class is to extend the Activity class in our MainActivity class, so we’ll do just that and leave the class alone.

MainActivity activity
MainActivity activity

From my previous post Android: An Introduction, we know that any Android App component needs to be registered with Android Manifest file located in manifests folder. So we add a new activity entry into the manifest file by creating a new <activity> tag and passing “android:name” field value, which is the complete path of the activity class.

Android Manifest XML File
Android Manifest XML File

If you have an android device connect to your PC with its developer options and USB debugging enabled you can skip creating an emulator to run your App and can directly jump onto the third part of this text as running an emulator is quite slow and taxing on your Computer’s hardware.

Building and Launching Android Virtual Device

To run/edit/create an android virtual device there is a AVD manager built inside Android SDK that can be accessed via Android studio tool bar or file menu. On the tool bar click on the phone looking icon with android robot head on the bottom on the toolbar(5th icon from the start in the below image).

Android Studio Toolbar
Android Studio Toolbar

Clicking the above AVD manager icon will launch the AVD manager and it will provide you options to modify/create/start your AVD. By default at least one AVD should be present for your reference, you can create new ones if you like or modify it as you like.

AVD Manager
AVD Manager

To create new AVD click on the “+ Create Virtual Device” and to edit the current AVD click on the pencil icon on right of the AVD info tuple. If you find everything in order just double-click on the AVD tuple to launch or click on the green arrow on the right. Now wait for some time till you see AVD running like below

Launched AVD
Launched AVD

This comes to the final part of this text launching our very first app via Android studio.

Running an Android App

Running your app is very straight forward, just run your Android project and select Activity to launch (if required) and done. Lets break this and go step by step, first click on the run button on the Android studio toolbar. It’s a green coloured arrow on the Studio’s toolbar.

Android Studio Toolbar
Android Studio Toolbar

This will ask you to edit launch configurations. Now just edit the activity name, go to activity field select launch radio button as below

AVD Configuration
AVD Configuration

Now click on the brows button above and select your App’s only activity “MainActivity”.

Select Launch Activity
Select Launch Activity

Now hit Run button, which will finally ask you where to run the App, select the AVD (can be selected even if it’s not running)  or the device connected to your system.

Choose Launch Device
Choose Launch Device

Click “OK” and you are good to go. Now just check the AVD or your personal device which ever you chose while running the App. It should now show your App running.

Launched App
Launched App

Congratulations, your very first Android App is up and running!

Though it cannot do anything as of now just showing blank page with activity name but it’s just a start there will be a lot more to come. Well I think it’s enough for this text hope you learned something, so until next time bye~.

PS: Do let me know if you find anything wrong in the text or you have any query(even though this one is not technical) using the comments so that I can modify it or try to explain things better.

Keep reading keep coding.
cheers!!

Published inAndroid

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *