How to make android apps
Here, we are going to create the simple hello android application using the Eclipse IDE. Follow the below steps:
- Create the new android project
- Write the message
- Run the android application
Create the New Android project
Follow the below steps to create a new android studio project:
- First select Start a new Android Studio project.
- Select the Activity type as Empty Activity.
- Click next.
- Feed the required information like Application name, Language, API level, Project location and Package name of the application.
- Click finish.
- A new android project is thus created. The activity class and the other required configuration files are auto-generated by the Android Studio.
Write the message:
The code for the activity_main.xml file is auto-generated by the Android Studio which can be edited as per the requirement.
File: MainActivity.java
package com.example.app1; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } |
File: activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" 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:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> |
After Editing:: File: activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" 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:text="Hello Code Java!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> |
Run the android application:
Simply press Shift + F10 or click the run icon on the toolbar to run the created android application.
It takes 2 or 3 minutes by the android emulator to boot. The application is installed and the activity is launched by the android studio after booting the emulator.
Internal Details of Hello Android Example:
Various components such as java source code, string resources, images, manifest file, apk file, etc are present in an Android application. Here, we will discuss the project structure of an android application.
Java Source Code:
The java source file created by the Eclipse IDE:
File: MainActivity.java
package com.example.app1; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } |
Activity:
To create a default window on the screen to place various components such as Button, EditText, TextView, Spinner, etc, the Activity is used which is a java class. The Activity can be understood as the Frame of Java AWT. The life cycle methods for an activity such as onCreate, onStop, OnResume, etc is provided by the Activity java class.
onCreate method:
When Activity class is first created, the onCreate method is called.
setContentView(R.layout.activity_main):
The information about the layout resource is provided by the setContentView(R.layout.activity_main). The layout resources, here, are defined in the activity_main.xml file.
File: activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" 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:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> |
A Textview is created by the framework automatically and the message for this string is defined in the strings.xml file. The information about the Textview message is provided by the @string/hello_world. The strings.xml file includes the definition of the value of the attribute hello_world. The value of the hello_world attribute can thus be changed from this file.
File: strings.xml
<resources> <string name="app_name">App1</string> </resources> |
Generated R.java file:
The IDs for all the resources of the res directory are present in the R.java file which is an auto-generated file, generated by the AAPT(Android Asset Packaging Tool). The corresponding ID of the component is created in the R.java file whenever a component is created on activity_main. It can later be used in the Java Source file.
File: R.java
* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * gradle plugin from the resource data it found. It * should not be modified by hand. */ package android.support.constraint; public final class R { private R() {} public static final class attr { private attr() {} public static final int barrierAllowsGoneWidgets = 0x7f020037; public static final int barrierDirection = 0x7f020038; public static final int chainUseRtl = 0x7f020046; public static final int constraintSet = 0x7f020059; public static final int constraint_referenced_ids = 0x7f02005a; public static final int content = 0x7f02005b; public static final int emptyVisibility = 0x7f020077; public static final int layout_constrainedHeight = 0x7f02009a; public static final int layout_constrainedWidth = 0x7f02009b; public static final int layout_constraintBaseline_creator = 0x7f02009c; public static final int layout_constraintBaseline_toBaselineOf = 0x7f02009d; public static final int layout_constraintBottom_creator = 0x7f02009e; public static final int layout_constraintBottom_toBottomOf = 0x7f02009f; public static final int layout_constraintBottom_toTopOf = 0x7f0200a0; public static final int layout_constraintCircle = 0x7f0200a1; public static final int layout_constraintCircleAngle = 0x7f0200a2; public static final int layout_constraintCircleRadius = 0x7f0200a3; public static final int layout_constraintDimensionRatio = 0x7f0200a4; public static final int layout_constraintEnd_toEndOf = 0x7f0200a5; public static final int layout_constraintEnd_toStartOf = 0x7f0200a6; public static final int layout_constraintGuide_begin = 0x7f0200a7; public static final int layout_constraintGuide_end = 0x7f0200a8; public static final int layout_constraintGuide_percent = 0x7f0200a9; public static final int layout_constraintHeight_default = 0x7f0200aa; public static final int layout_constraintHeight_max = 0x7f0200ab; public static final int layout_constraintHeight_min = 0x7f0200ac; public static final int layout_constraintHeight_percent = 0x7f0200ad; public static final int layout_constraintHorizontal_bias = 0x7f0200ae; public static final int layout_constraintHorizontal_chainStyle = 0x7f0200af; public static final int layout_constraintHorizontal_weight = 0x7f0200b0; public static final int layout_constraintLeft_creator = 0x7f0200b1; public static final int layout_constraintLeft_toLeftOf = 0x7f0200b2; public static final int layout_constraintLeft_toRightOf = 0x7f0200b3; public static final int layout_constraintRight_creator = 0x7f0200b4; public static final int layout_constraintRight_toLeftOf = 0x7f0200b5; public static final int layout_constraintRight_toRightOf = 0x7f0200b6; public static final int layout_constraintStart_toEndOf = 0x7f0200b7; public static final int layout_constraintStart_toStartOf = 0x7f0200b8; public static final int layout_constraintTop_creator = 0x7f0200b9; public static final int layout_constraintTop_toBottomOf = 0x7f0200ba; public static final int layout_constraintTop_toTopOf = 0x7f0200bb; public static final int layout_constraintVertical_bias = 0x7f0200bc; public static final int layout_constraintVertical_chainStyle = 0x7f0200bd; public static final int layout_constraintVertical_weight = 0x7f0200be; public static final int layout_constraintWidth_default = 0x7f0200bf; public static final int layout_constraintWidth_max = 0x7f0200c0; public static final int layout_constraintWidth_min = 0x7f0200c1; public static final int layout_constraintWidth_percent = 0x7f0200c2; public static final int layout_editor_absoluteX = 0x7f0200c4; public static final int layout_editor_absoluteY = 0x7f0200c5; public static final int layout_goneMarginBottom = 0x7f0200c6; public static final int layout_goneMarginEnd = 0x7f0200c7; public static final int layout_goneMarginLeft = 0x7f0200c8; public static final int layout_goneMarginRight = 0x7f0200c9; public static final int layout_goneMarginStart = 0x7f0200ca; public static final int layout_goneMarginTop = 0x7f0200cb; public static final int layout_optimizationLevel = 0x7f0200ce; } public static final class id { private id() {} public static final int bottom = 0x7f070021; public static final int end = 0x7f070036; public static final int gone = 0x7f07003d; public static final int invisible = 0x7f070047; public static final int left = 0x7f070049; public static final int packed = 0x7f070057; public static final int parent = 0x7f070058; public static final int percent = 0x7f07005a; public static final int right = 0x7f07005e; public static final int spread = 0x7f070076; public static final int spread_inside = 0x7f070077; public static final int start = 0x7f07007c; public static final int top = 0x7f07008b; public static final int wrap = 0x7f070091; } public static final class styleable { private styleable() {} public static final int[] ConstraintLayout_Layout = { 0x10100c4, 0x101011f, 0x1010120, 0x101013f, 0x1010140, 0x7f020037, 0x7f020038, 0x7f020046, 0x7f020059, 0x7f02005a, 0x7f02009a, 0x7f02009b, 0x7f02009c, 0x7f02009d, 0x7f02009e, 0x7f02009f, 0x7f0200a0, 0x7f0200a1, 0x7f0200a2, 0x7f0200a3, 0x7f0200a4, 0x7f0200a5, 0x7f0200a6, 0x7f0200a7, 0x7f0200a8, 0x7f0200a9, 0x7f0200aa, 0x7f0200ab, 0x7f0200ac, 0x7f0200ad, 0x7f0200ae, 0x7f0200af, 0x7f0200b0, 0x7f0200b1, 0x7f0200b2, 0x7f0200b3, 0x7f0200b4, 0x7f0200b5, 0x7f0200b6, 0x7f0200b7, 0x7f0200b8, 0x7f0200b9, 0x7f0200ba, 0x7f0200bb, 0x7f0200bc, 0x7f0200bd, 0x7f0200be, 0x7f0200bf, 0x7f0200c0, 0x7f0200c1, 0x7f0200c2, 0x7f0200c4, 0x7f0200c5, 0x7f0200c6, 0x7f0200c7, 0x7f0200c8, 0x7f0200c9, 0x7f0200ca, 0x7f0200cb, 0x7f0200ce }; public static final int ConstraintLayout_Layout_android_orientation = 0; public static final int ConstraintLayout_Layout_android_maxWidth = 1; public static final int ConstraintLayout_Layout_android_maxHeight = 2; public static final int ConstraintLayout_Layout_android_minWidth = 3; public static final int ConstraintLayout_Layout_android_minHeight = 4; public static final int ConstraintLayout_Layout_barrierAllowsGoneWidgets = 5; public static final int ConstraintLayout_Layout_barrierDirection = 6; public static final int ConstraintLayout_Layout_chainUseRtl = 7; public static final int ConstraintLayout_Layout_constraintSet = 8; public static final int ConstraintLayout_Layout_constraint_referenced_ids = 9; public static final int ConstraintLayout_Layout_layout_constrainedHeight = 10; public static final int ConstraintLayout_Layout_layout_constrainedWidth = 11; public static final int ConstraintLayout_Layout_layout_constraintBaseline_creator = 12; public static final int ConstraintLayout_Layout_layout_constraintBaseline_toBaselineOf = 13; public static final int ConstraintLayout_Layout_layout_constraintBottom_creator = 14; public static final int ConstraintLayout_Layout_layout_constraintBottom_toBottomOf = 15; public static final int ConstraintLayout_Layout_layout_constraintBottom_toTopOf = 16; public static final int ConstraintLayout_Layout_layout_constraintCircle = 17; public static final int ConstraintLayout_Layout_layout_constraintCircleAngle = 18; public static final int ConstraintLayout_Layout_layout_constraintCircleRadius = 19; public static final int ConstraintLayout_Layout_layout_constraintDimensionRatio = 20; public static final int ConstraintLayout_Layout_layout_constraintEnd_toEndOf = 21; public static final int ConstraintLayout_Layout_layout_constraintEnd_toStartOf = 22; public static final int ConstraintLayout_Layout_layout_constraintGuide_begin = 23; public static final int ConstraintLayout_Layout_layout_constraintGuide_end = 24; public static final int ConstraintLayout_Layout_layout_constraintGuide_percent = 25; public static final int ConstraintLayout_Layout_layout_constraintHeight_default = 26; public static final int ConstraintLayout_Layout_layout_constraintHeight_max = 27; public static final int ConstraintLayout_Layout_layout_constraintHeight_min = 28; public static final int ConstraintLayout_Layout_layout_constraintHeight_percent = 29; public static final int ConstraintLayout_Layout_layout_constraintHorizontal_bias = 30; public static final int ConstraintLayout_Layout_layout_constraintHorizontal_chainStyle = 31; public static final int ConstraintLayout_Layout_layout_constraintHorizontal_weight = 32; public static final int ConstraintLayout_Layout_layout_constraintLeft_creator = 33; public static final int ConstraintLayout_Layout_layout_constraintLeft_toLeftOf = 34; public static final int ConstraintLayout_Layout_layout_constraintLeft_toRightOf = 35; public static final int ConstraintLayout_Layout_layout_constraintRight_creator = 36; public static final int ConstraintLayout_Layout_layout_constraintRight_toLeftOf = 37; public static final int ConstraintLayout_Layout_layout_constraintRight_toRightOf = 38; public static final int ConstraintLayout_Layout_layout_constraintStart_toEndOf = 39; public static final int ConstraintLayout_Layout_layout_constraintStart_toStartOf = 40; public static final int ConstraintLayout_Layout_layout_constraintTop_creator = 41; public static final int ConstraintLayout_Layout_layout_constraintTop_toBottomOf = 42; public static final int ConstraintLayout_Layout_layout_constraintTop_toTopOf = 43; public static final int ConstraintLayout_Layout_layout_constraintVertical_bias = 44; public static final int ConstraintLayout_Layout_layout_constraintVertical_chainStyle = 45; public static final int ConstraintLayout_Layout_layout_constraintVertical_weight = 46; public static final int ConstraintLayout_Layout_layout_constraintWidth_default = 47; public static final int ConstraintLayout_Layout_layout_constraintWidth_max = 48; public static final int ConstraintLayout_Layout_layout_constraintWidth_min = 49; public static final int ConstraintLayout_Layout_layout_constraintWidth_percent = 50; public static final int ConstraintLayout_Layout_layout_editor_absoluteX = 51; public static final int ConstraintLayout_Layout_layout_editor_absoluteY = 52; public static final int ConstraintLayout_Layout_layout_goneMarginBottom = 53; public static final int ConstraintLayout_Layout_layout_goneMarginEnd = 54; public static final int ConstraintLayout_Layout_layout_goneMarginLeft = 55; public static final int ConstraintLayout_Layout_layout_goneMarginRight = 56; public static final int ConstraintLayout_Layout_layout_goneMarginStart = 57; public static final int ConstraintLayout_Layout_layout_goneMarginTop = 58; public static final int ConstraintLayout_Layout_layout_optimizationLevel = 59; public static final int[] ConstraintLayout_placeholder = { 0x7f02005b, 0x7f020077 }; public static final int ConstraintLayout_placeholder_content = 0; public static final int ConstraintLayout_placeholder_emptyVisibility = 1; public static final int[] ConstraintSet = { 0x10100c4, 0x10100d0, 0x10100dc, 0x10100f4, 0x10100f5, 0x10100f7, 0x10100f8, 0x10100f9, 0x10100fa, 0x101011f, 0x1010120, 0x101013f, 0x1010140, 0x101031f, 0x1010320, 0x1010321, 0x1010322, 0x1010323, 0x1010324, 0x1010325, 0x1010326, 0x1010327, 0x1010328, 0x10103b5, 0x10103b6, 0x10103fa, 0x1010440, 0x7f020037, 0x7f020038, 0x7f020046, 0x7f02005a, 0x7f02009a, 0x7f02009b, 0x7f02009c, 0x7f02009d, 0x7f02009e, 0x7f02009f, 0x7f0200a0, 0x7f0200a1, 0x7f0200a2, 0x7f0200a3, 0x7f0200a4, 0x7f0200a5, 0x7f0200a6, 0x7f0200a7, 0x7f0200a8, 0x7f0200a9, 0x7f0200aa, 0x7f0200ab, 0x7f0200ac, 0x7f0200ad, 0x7f0200ae, 0x7f0200af, 0x7f0200b0, 0x7f0200b1, 0x7f0200b2, 0x7f0200b3, 0x7f0200b4, 0x7f0200b5, 0x7f0200b6, 0x7f0200b7, 0x7f0200b8, 0x7f0200b9, 0x7f0200ba, 0x7f0200bb, 0x7f0200bc, 0x7f0200bd, 0x7f0200be, 0x7f0200bf, 0x7f0200c0, 0x7f0200c1, 0x7f0200c2, 0x7f0200c4, 0x7f0200c5, 0x7f0200c6, 0x7f0200c7, 0x7f0200c8, 0x7f0200c9, 0x7f0200ca, 0x7f0200cb }; public static final int ConstraintSet_android_orientation = 0; public static final int ConstraintSet_android_id = 1; public static final int ConstraintSet_android_visibility = 2; public static final int ConstraintSet_android_layout_width = 3; public static final int ConstraintSet_android_layout_height = 4; public static final int ConstraintSet_android_layout_marginLeft = 5; public static final int ConstraintSet_android_layout_marginTop = 6; public static final int ConstraintSet_android_layout_marginRight = 7; public static final int ConstraintSet_android_layout_marginBottom = 8; public static final int ConstraintSet_android_maxWidth = 9; public static final int ConstraintSet_android_maxHeight = 10; public static final int ConstraintSet_android_minWidth = 11; public static final int ConstraintSet_android_minHeight = 12; public static final int ConstraintSet_android_alpha = 13; public static final int ConstraintSet_android_transformPivotX = 14; public static final int ConstraintSet_android_transformPivotY = 15; public static final int ConstraintSet_android_translationX = 16; public static final int ConstraintSet_android_translationY = 17; public static final int ConstraintSet_android_scaleX = 18; public static final int ConstraintSet_android_scaleY = 19; public static final int ConstraintSet_android_rotation = 20; public static final int ConstraintSet_android_rotationX = 21; public static final int ConstraintSet_android_rotationY = 22; public static final int ConstraintSet_android_layout_marginStart = 23; public static final int ConstraintSet_android_layout_marginEnd = 24; public static final int ConstraintSet_android_translationZ = 25; public static final int ConstraintSet_android_elevation = 26; public static final int ConstraintSet_barrierAllowsGoneWidgets = 27; public static final int ConstraintSet_barrierDirection = 28; public static final int ConstraintSet_chainUseRtl = 29; public static final int ConstraintSet_constraint_referenced_ids = 30; public static final int ConstraintSet_layout_constrainedHeight = 31; public static final int ConstraintSet_layout_constrainedWidth = 32; public static final int ConstraintSet_layout_constraintBaseline_creator = 33; public static final int ConstraintSet_layout_constraintBaseline_toBaselineOf = 34; public static final int ConstraintSet_layout_constraintBottom_creator = 35; public static final int ConstraintSet_layout_constraintBottom_toBottomOf = 36; public static final int ConstraintSet_layout_constraintBottom_toTopOf = 37; public static final int ConstraintSet_layout_constraintCircle = 38; public static final int ConstraintSet_layout_constraintCircleAngle = 39; public static final int ConstraintSet_layout_constraintCircleRadius = 40; public static final int ConstraintSet_layout_constraintDimensionRatio = 41; public static final int ConstraintSet_layout_constraintEnd_toEndOf = 42; public static final int ConstraintSet_layout_constraintEnd_toStartOf = 43; public static final int ConstraintSet_layout_constraintGuide_begin = 44; public static final int ConstraintSet_layout_constraintGuide_end = 45; public static final int ConstraintSet_layout_constraintGuide_percent = 46; public static final int ConstraintSet_layout_constraintHeight_default = 47; public static final int ConstraintSet_layout_constraintHeight_max = 48; public static final int ConstraintSet_layout_constraintHeight_min = 49; public static final int ConstraintSet_layout_constraintHeight_percent = 50; public static final int ConstraintSet_layout_constraintHorizontal_bias = 51; public static final int ConstraintSet_layout_constraintHorizontal_chainStyle = 52; public static final int ConstraintSet_layout_constraintHorizontal_weight = 53; public static final int ConstraintSet_layout_constraintLeft_creator = 54; public static final int ConstraintSet_layout_constraintLeft_toLeftOf = 55; public static final int ConstraintSet_layout_constraintLeft_toRightOf = 56; public static final int ConstraintSet_layout_constraintRight_creator = 57; public static final int ConstraintSet_layout_constraintRight_toLeftOf = 58; public static final int ConstraintSet_layout_constraintRight_toRightOf = 59; public static final int ConstraintSet_layout_constraintStart_toEndOf = 60; public static final int ConstraintSet_layout_constraintStart_toStartOf = 61; public static final int ConstraintSet_layout_constraintTop_creator = 62; public static final int ConstraintSet_layout_constraintTop_toBottomOf = 63; public static final int ConstraintSet_layout_constraintTop_toTopOf = 64; public static final int ConstraintSet_layout_constraintVertical_bias = 65; public static final int ConstraintSet_layout_constraintVertical_chainStyle = 66; public static final int ConstraintSet_layout_constraintVertical_weight = 67; public static final int ConstraintSet_layout_constraintWidth_default = 68; public static final int ConstraintSet_layout_constraintWidth_max = 69; public static final int ConstraintSet_layout_constraintWidth_min = 70; public static final int ConstraintSet_layout_constraintWidth_percent = 71; public static final int ConstraintSet_layout_editor_absoluteX = 72; public static final int ConstraintSet_layout_editor_absoluteY = 73; public static final int ConstraintSet_layout_goneMarginBottom = 74; public static final int ConstraintSet_layout_goneMarginEnd = 75; public static final int ConstraintSet_layout_goneMarginLeft = 76; public static final int ConstraintSet_layout_goneMarginRight = 77; public static final int ConstraintSet_layout_goneMarginStart = 78; public static final int ConstraintSet_layout_goneMarginTop = 79; public static final int[] LinearConstraintLayout = { 0x10100c4 }; public static final int LinearConstraintLayout_android_orientation = 0; } } |
APK File:
The framework automatically creates an apk file. We need to transfer and install the apk file to the mobile to run the android application on the mobile.
Resources:
Resource files including activity_main, strings, styles, etc are present in resources.
Manifest file:
The information about the package including components such as activities, services, content providers, etc is present in the manifest file.