Pages

Saturday, April 23, 2016

Execution Flow of Android Application

As a Beginner You need to know the execution flow of your android application. to understand the basic execution flow of android  we are  considering the hello world example.

When you create the android project in eclipse lots of folder are created such as "src" ,"gen" , "Android 1.5"  , "assets" and "res" folder.
To understand android flow we are starting with the "res" folder. In "res" folder there is a file called "AndroidManifest.xml".
These below is the content of AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest
      package="com.example"
      android_versionCode="1"
      android_versionName="1.0">
    <uses-sdk android_minSdkVersion="3" />
    <application android_icon="@drawable/icon" android_label="@string/app_name">
        <activity android_name=".HelloWorldDemo"
                  android_label="@string/app_name">
            <intent-filter>
                <action android_name="android.intent.action.MAIN" />
                <category android_name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      
    </application>
</manifest>

In the Above Xml code we have an activity called "HelloWordDemo" listed in activity tag this activity will be launched first. if you have multiple activity in your android application you must have to register all your activity in AndroidManifest.xml file.
you can specify your child activity by just <activity android_name=".xyz"></activity> adding as many tag as many activity you have in your android application. Make sure you specify "." (dot) before each activity.
Activity name ".HelloWorldDemo" will call HelloWorldDemo.java file.
package com.example;
import android.app.Activity;
import android.os.Bundle;
public class HelloWorldDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
When HelloWorldDemo Activity is created by default onCreate method will be executed. inside onCreate Method we have an setContentView which execute the android application design file whose name is main.xml  because we have R.layout.main as an argument.
In Brief  AndroidManifest.xml file execute the Launcher Activity class and from the launcher activity onCreate method will execute the Design View file by using setContentView method.


Android Apk

Related Posts by Categories

0 comments:

Post a Comment