Quick Contact


    Internal Details of Hello Android Example

    Here, we’ll look at the internals of the hello android example and how it works.

    Different components of an Android programme include java source code, string tools, images, manifest files, and apk files, among others. Let’s look at the framework of an Android device project.

    Hello Android Example
    Java Source Code

    Let’s look at the Java source file that the Eclipse IDE generated:

    File: MainActivity.java

    package com.helloandroid Studio;

    import android.os.Bundle;

    import android.app.Activity;

    import android.view.Menu;

    import android.widget.TextView;

    public class MainActivity extends Activity

    {

    Override

    protected void onCreate;

    {

    super.onCreateState;

    setContentView(R.layout.activity_main);

    }

    @Override

    public booleanonCreateOptionsMenu(Menu menu)

    {

    // Inflate the menu; If the action bar is present, this attaches elements to it.

    getMenuInflater().inflate(R.menu.activity_main, menu);

    return true;

    }

    }

    1. Activity is a Java class that generates a default display on the window where we can position various elements including Button, EditText, TextView, Spinner, and so on. It’s similar to the Java AWT Frame.
    2. It includes life cycle strategies for activities like onCreate, onStop, and OnResume, among others.

    3. Whenever the Activity class is first generated, the onCreate method is named.
    4. The setContentView(R.layout.activity main) function returns data about our layout resource. In the activity main.xml format, we describe our layout tools.

    File: activity_main.xml

    < RelativeLayoutxmlns:androclass="http://schemas.android.com/apk/res/android"

    xmlns:tools=”http://schemas.android.com/tools”

    android:layout_width=”match_parent”

    android:layout_height=”match_parent”

    tools:context=”.MainActivity” >

    < TextView

    android:layout_width=”wrap_content”

    android:layout_height=”wrap_content”

    android:layout_centerHorizontal=”true” ;

    android:layout_centerVertical=”true” ;

    tools:context=”.MainActivity” >

    android:layout_height=”match_parent”

    android:text=”@string/hello_world” />

    < /RelativeLayout>

    As you can see, the code dynamically creates a textview. The notification for this string, on the other hand, is defined in the strings.xml format. @string/hello world is a string that provides data about the textview post. In the strings.xml format, the value of the variable hello world is defined.

    File: strings.xml

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

    < resources>

    < string name="app_name">helloandroidStudio< /string>

    < string name="hello_world">Hello world!< /string>

    < string name="hello_world1">Hello world!< /string>

    < string name="hello_world2">Hello world!< /string>

    < string name="menu_settings">Settings< /string>

    < /resources>

    This file allows you to adjust the value of the hello world variable.

    R.java file

    It’s an auto-generated file that lists all of the tools in the res directory and their IDs. It is produced by aapt (Android Asset Packaging Tool). Once you build a part on activity main, an ID is provided in the R.java file that you can later use in the Java Data source.

    File: R.java

    /* AUTO-GENERATED FILE. DO NOT MODIFY.

    *

    * The aapt tool created this class spontaneously

    * from the information resources it discovered. It should not be altered manually.

    */

    package com.example.helloandroid;

    public final class R {

    public static final class drawable is a public static final class.

    {

    ic launcher=0x7f020000;

    public static final int ic launcher=0x7f020000;

    }

    public static final class id menu settings=0x7f070000;

    public static last int menu settings=0x7f070000;

    }

    design public static final class public static final class layout

    {

    public static final class layout public static final class layout

    publicactivity main=0x7f030000;

    public static final int activity main=0x7f030000;

    }

    final static public class menu {

    activity main=0x7f060000;

    public static final int activity main=0x7f060000;

    {

    protected static final class string public static final int app name=0x7f040000;

    public static final int hello world=0x7f040001;

    public static final int menu settings=0x7f040002;

    public static final int app name=0x7f040000;

    public static final int app name=0x7f040000;

    public static final int app name=0x7f040000;

    public static final int app name=Hello_World

    /**

    Theme for the base function, which is determined by the API level. On newer computers, AppBaseTheme from res/values-vXX/styles.xml replaces this theme.

    Theme customizations are also available in newer API levels.

    Enhancements related to res/values-vXX/styles.xml, whereas customizations related to

    This is where reverse compatibility can be found.

    Theme modifications for API 11 can be found here.

    Theme for API 14+ applications. This theme totally replaces the previous one.

    AppBaseTheme from The other res/values/styles.xml and res/values/styles.xml

    on API 14+ computers, res/values-v11/styles.xml

    Theme enhancements for API 14 can be found here.

    Style for the application.

    This is where you can put some customisation options that aren’t unique to a specific API level.

    public static final int AppTheme=0x7f050001;

    }

    }

    Manifest file

    It includes information about the kit, including events, programmes, content suppliers, and so on.

    Visit the AndroidManifest.xml file for more details on the specified directory.

    Enroll Yourself in Live Classes For Android Training Online.

    Copyright 1999- Ducat Creative, All rights reserved.