Android

Create your first android app – Hello Android! using Android Studio

Here i am going to split entire process of Hello Android application creation into 5 steps. Which are as follows,

Step 1: Create a new project
Step 2: Create an activity
Step 3: Create a layout for the activity
Step 4: Add activity to AndroidManifest.xml
Step 5: Build & Run

Create a new project

Here i use android studio built-in project creation wizard which is very simple and helpful especially for the beginners. I recommend android studio.

Select “start a new android project” from the option list on the right panel of the window.

Capture1

Here you can set your package name. Which is the only one unique identifier of your app as far as the android operating is concerned. When you upload your apk to Google Playstore they check uniqueness of the package name.

Capture2

Target a device and select the minimum sdk that your app supports, where 8 is recommended but we use 15 for now.

Capture3

Here we can select the type of the activity that is going to be created soon after this wizard finished. You should carefully select one of them because it depends on features of your application. Now we select a blank activity.

Capture4

This is the final screen of the wizard when you press “finish” button it will create all the files needed for the application.

Capture5

Activity is an component of android application. For creating an activity we have to create a class that extends Activity base class. This extension makes the class an activity. When we create an activity class we should inherit onCreate method of super class. This is the callback function when activity creates.

onCreate method has a super class method called setContentView. As per an activity this is an important method. By this we can mention out layout file.

Capture10

Step 2: Create a layout for the activity.

create a xml file inside layout folder with desired name. I name it “activity_main”

Capture8

Edit value of “android:text” activity_main.xml

1
2
<TextView android:text="Hello Android" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Add activity to AndroidManifest.xml

Activity should be added in this file. AndroidManifest.xml acts like a configuration file of your application. If you don’t add then it will show error. If you are creating activity using Android studio wizard then it will be created automatically. Here it is autogenerated.

manifest_activity

An application may have multiple activities. Consider a case in which we have multiple activities android operating system gets confused on which is the first activity to be executed. The below shown code indicates that this activity is the first one to be executed.

1
2
3
4
<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Since we have only one activity here we don’t have to worry about that.

launcher tag

Build & Run

This step will create apk from your code and install it into your test device/emulator.
Capture11

If you have any queries on this topic please ask through comment section.
Thanks & good luck!

About author

Rojer is a programmer by profession, but he likes to research new things and is also interested in writing. Devdeeds is his blog, where he writes all the blog posts related to technology, gadgets, mobile apps, games, and related content.

Leave a Reply

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