Android :Learn to make your own Android App

Android applications are in great demand in the market ,and that how it attarcts more freaky programmers to develop apps for Android. Today ,I am going to demonstrate how to display any text in the Android App .

If you are newbie to Java,then this is not the right place for you,just brush up Java before you start here.At first you need to install Android SDK as per your system.For installation help click here http://developer.android.com/sdk/installing/index.html

NOW FOLLOW THE FOLLOWING STEPS
STEP 1: Start Eclipse.Once it is started.Go to File

File->New->Android Application Project.

android1

A dialog box will appear ,name is whatever you wish like i have given it name as Android_1
If you are asked to select a build target,and if you have installed Android API,choose API level as shown in the picture below.
android 4
Once selected click Next.
NOTE: The name of the package should be unique as once you will upload this app to Google Android marketplace.You Android App will be recognized with unique package name.

STEP 2: Now we need to create an activity.Activity is basically the layout structure that we want to display in our App.
Select Blank Activity on clicking next after Step 1.
Give the name of the Activity as I have given the name of the activity as Android_test
and click Finish
a6-03-15 12:03:36

FInally go to Window->AVD Manager and start your target emulator( An emulator is a virtual Android device to run Android Apps ).

STEP 3: Go to ECLIPSE  and see the Project Explorer ,and you will see all the files  listed in your project like the following image.

a7

Now open AndroidManifest.xml and you will find the codes as

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android_1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.android_1.Android_test"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".Second_activity" android:label="@string/app_name"/>

    </application>

</manifest>

Brief Explanation about AndroidManifest.xml:-

AndroidManifest.xml file contains app specific settings such as app version and minimum SDK version.The different permissions required,activities that can be run,services,broadcast receives and more.
Once open,it will open in default graphical view,change it into AndroidManifest.xml view at the bottom right of your view of the manifest .
At the top level under application you are specifying icons and label.The main function of intent filter stuff is that it specifies what should launch when an App runs.

And again go to project Explorer and search for “res” folder and res->values>string.xml and the string.xml will open like shown below .

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">android_1</string>
    <string name="hello_world">Hello world! THIS IS MY ANDROID TUTORIAL</string>
    <string name="menu_settings">Settings</string>
     <string name="test_one"> THIS IS MY FIRST ANDROID PROGRAM</string>
     <string name="click_me">Click Me</string>

</resources>

you will see that two strings are already created.If you look at the AndroidManifest.xml file ,you will find
@String/app_name.It is referring to the app_name string seen here.This string.xml is basically a resource file.These are heavily used in Android to make it easier to localize your application.
Again move on to res/layout/activity_android_test.xml.You will see a file a like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@string/click_me"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Android_test" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        android:id="@+id/lblTextViewOne" />


    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginLeft="64dp"
        android:layout_marginTop="39dp"
        android:onClick="@string/test_one"
        android:text="CLICK ME" />
</RelativeLayout>

Relative Layout is the way of containing and organizing element inside of it.The Relative Layout is used to display a block of text.

STEP 3: Now go to src->com.Example.Android_1
and open the Android_test.java file once there.And write the code as given given:

package com.example.android_1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Android_test extends Activity {

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

		final TextView TextViewOne = (TextView) findViewById(R.id.TextViewOne);
		TextViewOne.setText(R.string.test_one);

		}

}

Explantation of Android_test.java
Android_test class is extending the Activity class (which is part of Android SDK).We are only overriding one method from the Activity subclass,the “onCreate” method .This method is called when the activity is created and also when the screen is rotated.We call super.onCreate method so that the Activity subclass can handle its plumbing and then we call setContentView .This method is passed R.Layout.main .R is a way to refer to res folder and is how we pro-grammatically access the items in that folder.

STEP 4:
All we need to do is to create a new string and then use your TextView to use that String in the onCreate method.
let’s add an string to string.xml

<stringname="test_one">This is my first App</string>

Screenshot from 2013-03-15 12:25:29
then go back to activity_android_test.xml/main.xml

and add an id to it like

android:id="@+id/newtext"

again go to Android_test.java and write the following code

 TextView newtext=(TextView)findViewById(R.id.newtext)

if there is an error coming just import “TextView” or (android.widget)
again set the property of the Textview as

TextViewOne.setText(R.string.test_one);

Now your app is ready is ready to run.Just clean and build and RUN AS ANDROID APPLICATION
You will see an updated text.

Advertisements

2 thoughts on “Android :Learn to make your own Android App

  1. This is very inspiring, as getting from the start & Having no real background in programming (aside from making some adventures on ZX-81 and MSX), this does sound like I could get started on developing something for my own Android based eBook reader and android app development training even this online course seems to be interesting http://www.wiziq.com/course/13599-professional-android-app-development-training-1-on-1-sessions. Has anyone tried any online courses so far. Please do provide a light on this also.

    Thankyou for all the info also.

  2. This is very good publishing regarding Android Application development . Android application is an open source so everyone can learn it. It is very good & useful article for those who want to learn about android application development.

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