Android: Creating and Running first Android app

To start working on android 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 and will contain information regarding android development that can be used on Android Studio, Eclipse or any other 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.

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.

Create new project wizard

Create new project wizard

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.

Target Android Devices

Target Android 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.

Add an activity to Mobile page

Add an activity to Mobile page

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.

Android Studio with Project set up.

Android Studio with Project set up.

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.

Project Explorer

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”.

Create new Class

Create new Class

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 Class

MainActivity Class

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.

Add Activity to Manifest File

Add Activity to Manifest 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).

Launch AVD Manager

Launch AVD Manager

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

AVD Running

AVD Running

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.

Run Button

Run Button

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

Edit Launch Configuration

Edit Launch 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 Device

Choose 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.

App Running

App Running

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 learnt 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: