Skip to main content

Create a simple Android application

In this part i am going to explain how to create a simple android application. Before start the topic make sure that you have the following tools available in your computer. If not please go to the topic "Prepare PC for android development".
1. jdk 1.7
2. Eclipse IDE.
3. ADT for eclipse.
4. Android SDK.
5. AVD
For creating a new project just open up the eclipse IDE and follow the steps given bellow.
Step 1:
Click File ---> New --> Project
Step 2:
You got a new project window and choose android application project from it and click next.
Click image for full size
Step 3:
In the next window  you have to fill up three fields, Application name, project name and Package name.
Provide any appropriate name for project and application starting with capital letter. It is also possible to use same name for project and application.
Step 4:
Provide a package name for your project starting with "com." . For making your apps unique it is recommended that you have to use reverse of your domain name as the package name.
Step 5:
You have to choose a minimum required sdk version for your apps. Select the most older version as minimum sdk. This will ensure that your application will run on older platform also.
Step 6:
You have to specify a target SDK version. Select the latest version as target.
Step 7:
Choose the latest version for compile with drop list.
Step 8:
Choose any theme for your application and click next.

Click image to view full size
Step 9:
Select the crate custom launcher icon and create activity check box in the new window and click next.
Step 10:
In the next window, you have an option for choosing your own launcher icon for your application. If you want your own icon for your app, then chose it and click next. If you not specify any launcher icon image, your app get a default android app icon. Click next.
Click the image for full size
Step 11:
In the next window you have to choose create a blank activity and click next.
Step 12:
In the next window you have to specify the name for your activity and layout and click finish. Here i name it as First and first_layout. Always specify the activity name in capital letters because it representing a java class in our project. The layout name must be specified in small letter.
After doing all the above steps, your project is created in the ide and you can see it in the project explorer window. The project is for displaying a greeting message on the screen. The codes for the project is given bellow. For more information see the video tutorial of this topic.
You can find the First.java file from package present in the src folder and the first_layout.xml  find from the layout folder under the resource folder.
first_layout.xml 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".First" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="WELCOME ALL" />

</RelativeLayout>
test 

First.java

package com.example;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class First extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_layout);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.first, menu);
        return true;
    }

}




Click image to enlarge

 

Comments

Popular posts from this blog

Android MySQL Database Operations

In this post we are going to learn about how to connect to MySQL Database from your Android Application and perform database operations. Here we create an android app that contain some login Activity through which the user can retrieve information from database and a registration Activity through which the user can add information into the database.  First you need to have the following components installed in your development machine.  1. Database : Here we use the MySQL database. 2. Web Server : Here we use the Apache Web Server. 3. Server side Scripting Language :   Here we use PHP for server side scripting. 4. Android Development environment : You must install android sdk and android studio.   I recommend you to download and install WAMPSERVER. The wamp server installer contains the following components. Apache Server Application MySQL Database PHP/phpMyAdmin First we have to create the database and table in MySQL. You can use the...

Schedule Android Background Job Using Firebase JobDispatcher

From Android version 8.0 (Oreo) on wards there are limitations in executing background services and there are some limitations in receiving certain broadcasts. The android team implement all these restrictions to improve app performance and device battery life. If your app target API 26 then you have to consider some other mechanisms to do your background job.  Fortunately there is JobScheduler API that solve the problem regarding the background job limitations in newer versions of android. Google suggests Android App developers to use the JobScheduler API for their background job execution rather than using a background service.  But the problem is that the android framework JobScheduler API is available from android API version 21(Lollipop) and above. If your app support start from Lollipop and above then you can go for the framework JobScheduler API for your background job. If your App support start from android API lower than 21 then you can use the Firebase ...

"please correct the errors on this form" adsense error simple solution

Many of the bloggers now facing the problem with their adsense widgets. Whenever try to add the new  adsense link unit using the blogger widgets, it shows the error " please correct the errors on this form " as shown bellow. In blogger you can add the adsense units in two ways. First one is adding the adsense using the blogger widgets(Most of the beginners doing this) and the second method is to obtain the adsense code from the adsense login page and place it into the targeted position on the blog. To improve the revenue from adsense you have to place the appropriate ad unit into the right position. The adsense link units are very important for increasing the adsense revenue. So due to this error many of the bloggers are unable to place the link units.  Here is the solution for the problem. 1. Login into your adsense and blogger account. 2. Now make sure that only two adsense widgets (units) are present on your blog, this is because Google allows onl...