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.
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.
Target a device and select the minimum sdk that your app supports, where 8 is recommended but we use 15 for now.
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.
This is the final screen of the wizard when you press “finish” button it will create all the files needed for the application.
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.
Step 2: Create a layout for the activity.
create a xml file inside layout folder with desired name. I name it “activity_main”
Edit value of “android:text” activity_main.xml
<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.
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.
<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.
Build & Run
If you have any queries on this topic please ask through comment section.
Thanks & good luck!